【问题标题】:www. 301 redirect with parameters万维网。带参数的301重定向
【发布时间】:2013-10-13 18:06:23
【问题描述】:

我目前使用以下重定向使网址看起来更好:

RewriteRule profile/(.*) index.php?id=$1
(Result: domain.co.uk/profile/00000001)
From index.php?id=00000001

我想 301 将不带 www 的网址重定向到 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

【问题讨论】:

    标签: .htaccess mod-rewrite redirect web


    【解决方案1】:

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

    所以这应该有效:

    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]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-02
      • 1970-01-01
      • 1970-01-01
      • 2015-11-15
      • 2015-01-09
      • 2014-01-06
      • 2014-08-22
      • 2016-10-09
      相关资源
      最近更新 更多