【发布时间】:2016-07-19 15:00:11
【问题描述】:
我刚刚意识到我的 htaccess 在某些情况下会产生双 301 重定向。例如,如果您尝试访问http://example.com/old_url,它将:
- 前 301 到 http://www.example.com/old_url(添加 www)
- 然后 301 到 http://www.example.com/new_url(更改为新网址)
这是我的 htaccess 的设置方式:
RewriteEngine On
# Add www
RewriteCond %{HTTP_HOST} ^example.com [nocase]
RewriteRule ^(.*) http://www.example.com/$1 [last,redirect=301]
# Do some url rewriting
RewriteRule ^new_url_1$ new_url_1.php [NC,L]
RewriteRule ^new_url_2$ new_url_2.php [NC,L]
# Do the 301 redirections
Redirect 301 /old_url_1 http://www.example.com/new_url_1
Redirect 301 /old_url_2 http://www.example.com/new_url_2
我怎样才能解决这个问题,只有一个 301 以获得更好的 SEO?
【问题讨论】:
标签: apache .htaccess url redirect http-status-code-301