正则表达式 – 将网址从http://example.com/blog/重写为http://b
发布时间:2020-12-14 05:57:26 所属栏目:百科 来源:网络整理
导读:我应该使用什么RewriteRule(使用.htaccess / mod_rewrite)将http://example.com/blog/(带或不带www)重定向到http://blog.example.com/? 我正在使用以下内容,但获得重定向循环: RewriteEngine OnRewriteCond %{HTTP_HOST} !^www.example.com [NC]RewriteR
我应该使用什么RewriteRule(使用.htaccess / mod_rewrite)将http://example.com/blog/(带或不带www)重定向到http://blog.example.com/?
我正在使用以下内容,但获得重定向循环: RewriteEngine On RewriteCond %{HTTP_HOST} !^www.example.com [NC] RewriteRule ^(.*)$http://www.example.com/blog/ [L,R=301] RewriteCond %{HTTP_HOST} www.example.com [NC] RewriteRule ^(.*)$http://www.example.com/blog/ [L,R=301] 解决方法
在你现有的规则中,你似乎有一些错误的方法,我认为不需要负面(即!)测试.
RewriteEngine On RewriteCond %{HTTP_HOST} ^(www.)?example.com [NC] RewriteRule ^/blog/$http://blog.example.com/ [L,R=301] 但是,我建议您不要使用RewriteCond指令来检查主机名,只需确保规则位于www.example.com的正确VirtualHost中. <VirtualHost ...> ServerName www.example.com ServerAlias example.com RewriteRule ^/blog/ http://blog.example.com/ [L,R=301] </VirtualHost> (nb:假设blog.example.com和www.example.com实际上是独立的虚拟主机) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |