Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess www.301带参数重定向_.htaccess_Mod Rewrite_Redirect_Web - Fatal编程技术网

.htaccess www.301带参数重定向

.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=

我目前使用以下重定向使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=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]