RewriteRule帮助

时间:2011-08-05 12:25:06

标签: apache url-rewriting

我有一个网址

http://test.devsite-1.com/test/tbox/

我想重定向到

http://tbox.devsite-1.com/

规则:

RewriteCond %{HTTP_HOST}  !^tbox\.(.*)$  [NC]
RewriteCond %{HTTP_HOST}  ^(www\.|)(.*)$  [NC]
RewriteCond %{REQUEST_URI}  ^/tbox(/.*|)$ 
RewriteRule /tbox/(.*)  http://tbox.%{HTTP_HOST}/$1 [R=301,L]

我不明白为什么不将我重定向到网址?请注意,我需要一个通用规则,以便在我将test.devsite-1.com更改为tempo.devsite-1.com时,同样适用于其他网址。

1 个答案:

答案 0 :(得分:1)

尝试此规则:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^test\.(.+)$ [NC]
RewriteRule ^test/tbox/(.*)$ http://tbox.%1/$1 [R=301,L]

这将重定向(301永久重定向)

http://test.devsite-1.com/test/tbox/something-optional

http://tbox.devsite-1.com/something-optional
  1. 必须将其放在网站根文件夹中的.htaccess文件中(例如http://test.devsite-1.com/.htaccess)。如果放在其他地方,可能需要进行一些调整。
  2. 仅当请求来自test.子域名时才会生效。
  3. 只有在请求的网址以test/tbox/开头时才能使用。
  4. 以上所有内容都与您的网址示例相符。

相关问题