0

我目前使用以下重定向使 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 时,URL 如下所示:

http://www.DOMAIN.co.uk/index.php /00000001 ? id=00000001

我假设可以做到这一点,这是否需要根据我的需要定制,或者我是否缺少某些东西?

理想情况下,最终结果将重写:

domain.co.uk/profile/00000001

www.domain.co.uk/profile/00000001

4

1 回答 1

0

保持规则的正确顺序,即在内部重写之前保持外部重定向。

所以这应该工作:

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]
于 2013-10-13T10:06:23.173 回答