【问题标题】:How to redirect non www to www using htaccess in wordpress如何在wordpress中使用htaccess将非www重定向到www
【发布时间】:2014-05-17 11:08:28
【问题描述】:

我想将这两个网址 http://example.com/robots.txthttp://example.com/sitemap.xml 重定向到 http://www.example.com/robots.txthttp://www.example.com/sitemap.xml

此外,我还将我的 http://example.com 重定向到 http://www.example.com,但站点地图和机器人同时在 url(非 www)和(www)中打开,所以我只希望它只以 www 格式打开。

我尝试使用以下代码

RewriteRule sitemap\.xml  http://example.com/sitemap. [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

RewriteRule ^sitemap\.xml http://www.example.com/sitemap.xml [L,R=301]

但对我没有用,请帮我解决这个问题。

【问题讨论】:

    标签: php xml wordpress .htaccess redirect


    【解决方案1】:

    您的第一个重定向规则是错误的。使用这个:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^(sitemap\.xml|robots\.txt)$  http://www.%{HTTP_HOST}/$1 [L,R=301,NC]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L]
    

    【讨论】:

      猜你喜欢
      • 2018-05-26
      • 1970-01-01
      • 1970-01-01
      • 2012-10-19
      • 1970-01-01
      • 2018-11-12
      • 2012-11-16
      • 2010-11-12
      相关资源
      最近更新 更多