.htaccess www.301带参数重定向
我目前使用以下重定向使URL看起来更好:.htaccess www.301带参数重定向,.htaccess,mod-rewrite,redirect,web,.htaccess,Mod Rewrite,Redirect,Web,我目前使用以下重定向使URL看起来更好: RewriteRule profile/(.*) index.php?id=$1 (Result: domain.co.uk/profile/00000001) From index.php?id=00000001 我想301将不带www的URL重定向到www,并保持上述配置文件重定向 RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=
RewriteRule profile/(.*) index.php?id=$1
(Result: domain.co.uk/profile/00000001)
From index.php?id=00000001
我想301将不带www的URL重定向到www,并保持上述配置文件重定向
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
但是,当使用此选项时,URL显示为:
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]