htaccess的"静音"重定向

问题描述:

我有我的htaccess的就有点麻烦了,也许你能帮助我。
我想重定向我的要求是这样的:

i am having a bit trouble on my htaccess and maybe you could help me.
I want to redirect my requests like this:

www.fakedomain.mydomain.com/dev> www.mydomain.com/dev/events/fakedomain.php

该HTTP_HOST将fakedomain.mydomain.com我猜,但开发部分也很重要。我最后的尝试是:

www.fakedomain.mydomain.com/dev > www.mydomain.com/dev/events/fakedomain.php

The HTTP_HOST would be fakedomain.mydomain.com i guess, but the dev part is important too. My last try was :

RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.mydomain\.com [NC]
RewriteRule  ^(.*)$ /dev/events/%2 [L]

此重定向显示在浏览器顶部,这是我想避免的。
感谢您的时间

This redirect is shown at the top of the browser, something I want to avoid.
Thank you for your time

如果您使用的是 DOCROOT /的.htaccess 对于这一点,你应该使用:

If you are using your DOCROOT/.htaccess for this, you should use:

RewriteEngine On
RewriteBase   /

RewriteCond %{HTTP_HOST}         ^(www\.)?(\w+)\.mydomain\.com  [NC]
RewriteRule ^dev/(?!events/)     dev/events/%2.php              [L]

(?!事件/)位的正则表达式中被称为前向断言,这prevents规则匹配的/ dev /事件/某事,因此prevents重写循环。

The (?!events/) bit of the regexp is called a lookahead assertion and this prevents the rule matching /dev/events/something and hence prevents a rewrite loop.

如果您使用的是 DOCROOT的/ dev /的.htaccess 对于这一点,你应该使用:

If you are using your DOCROOT/dev/.htaccess for this, you should use:

RewriteEngine On
RewriteBase   /dev

RewriteCond %{HTTP_HOST}      ^(www\.)?(\w+)\.mydomain\.com  [NC]
RewriteRule ^(?!events/)      events/%2.php                  [L]

(?!事件/)位的正则表达式中被称为前向断言,这prevents规则匹配的/ dev /事件/某事,因此prevents重写循环。

The (?!events/) bit of the regexp is called a lookahead assertion and this prevents the rule matching /dev/events/something and hence prevents a rewrite loop.