【发布时间】:2013-09-16 01:18:33
【问题描述】:
到目前为止,我已经使用此代码将请求从 example.com/url/to/page 重定向到 www.example.com/url/to/page
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
最近我在我的页面上添加了 example.com/x/abc 之类的短链接 这些链接的开头不应有“www”
我试过了
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{REQUEST_URI} !^x/ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
但这不起作用。 Firebug 显示 2 个重定向:非 www 到 www,然后短链接到长链接,而不是仅 1 个重定向短链接到长链接。每次更改 .htaccess 时,我也会清空缓存
如何实现正确的重定向?
【问题讨论】:
标签: apache .htaccess redirect mod-rewrite subdirectory