![](/img/trans.png)
[英]Is it better to 301 redirect requests to a www. subdomain or non-www?
[英]www. 301 redirect with parameters
我目前使用以下重定向使网址看起来更好:
RewriteRule profile/(.*) index.php?id=$1
(Result: domain.co.uk/profile/00000001)
From index.php?id=00000001
我想将没有www的 301 网址重定向到www。 并保持上述配置文件重定向 。
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
但是,使用此URL时,URL如下所示:
http://www.DOMAIN.co.uk/ index.php / 00000001 ?id = 00000001
我以为这是可以做到的,是否需要根据我的需要量身定制,还是我缺少什么?
理想情况下,最终结果将被重写:
domain.co.uk/profile/00000001
至
www.domain.co.uk/profile/00000001
保持规则正确顺序,即在内部重写之前保持外部重定向。
所以这应该工作:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?id=([^\s&]+) [NC]
RewriteRule ^ %1? [R=301,L]
# internal forward from pretty URL to actual one
RewriteRule ^profile/(.+)$ index.php?id=$1 [L,QSA,NC]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.