Apache 重写规则帮助
我有一个网址Apache 重写规则帮助,apache,url-rewriting,Apache,Url Rewriting,我有一个网址 http://test.devsite-1.com/test/tbox/ 我想重定向到它 http://tbox.devsite-1.com/ 规则: 我不明白为什么它没有将我重定向到URL?请注意,我需要一个通用规则,这样,如果我将test.devsite-1.com更改为tempo.devsite-1.com,同样的规则也可以用于其他URL。尝试此规则: RewriteEngine On RewriteCond %{HTTP_HOST} ^test\.(.+)$ [NC]
http://test.devsite-1.com/test/tbox/
我想重定向到它
http://tbox.devsite-1.com/
规则:
我不明白为什么它没有将我重定向到URL?请注意,我需要一个通用规则,这样,如果我将test.devsite-1.com
更改为tempo.devsite-1.com
,同样的规则也可以用于其他URL。尝试此规则:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^test\.(.+)$ [NC]
RewriteRule ^test/tbox/(.*)$ http://tbox.%1/$1 [R=301,L]
这将重定向(301永久重定向)
到
http://test.devsite-1.com/.htaccess
)。如果放置在其他位置,可能需要进行一些调整test.
子域发出请求时,它才会工作test/tbox/
开头时,它才会起作用以上所有内容都与您的URL示例相匹配。修改的重写规则(.*{HTTP_HOST}/$1[R=301,L]……这些是我无法解决的问题……如果请求是通过
test.devsite-1.com
发出的,那么tbox.%{HTTP_HOST}
将生成tbox.test.devsite-1.com
——这显然是错误的({HTTP_HOST}
包含完整的域名,而不仅仅是devsite-1.com
)。您能告诉我%1和$1之间的区别吗?$1
是对重写规则模式(^test/tbox/(.*)
中的第一个匹配组的反向引用虽然%1
是反向引用,但在RewriteCond
模式中(^test\(.+)$
)。详情如下:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^test\.(.+)$ [NC]
RewriteRule ^test/tbox/(.*)$ http://tbox.%1/$1 [R=301,L]
http://test.devsite-1.com/test/tbox/something-optional
http://tbox.devsite-1.com/something-optional