我似乎无法弄清楚如何将旧网址https://www.mydomain.com/old_url/
重定向到https://www.mydomain.com/new_url/
我目前在我的htaccess中有以下内容(请注意与此问题相关的第二条规则):
RewriteEngine On
# SSL redirect
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteRule ^(.*) https://www.mydomain.com$1 [R=301,nc]
RewriteCond %{THE_REQUEST} ^GET\ /old_url/
RewriteRule ^/old_url$ https://www.mydomain.com/new_url [R=301,nc]
# If the root has a querystring with at least 1 character
RewriteCond %{QUERY_STRING} ^.+
RewriteRule ^/?$ https://www.mydomain.com/new_home_page [R=301,nc]
如果有所作为,我也会使用Django。非常感谢任何帮助。
答案 0 :(得分:1)
而不是:
RewriteCond %{THE_REQUEST} ^GET\ /old_url/
RewriteRule ^/old_url$ https://www.mydomain.com/new_url [R=301,nc]
你可以试试这个:
RewriteCond %{REQUEST_URI} old_url/(.*)
RewriteRule .* https://www.mydomain.com/new_url/%1 [R=301,QSA,NC]
将重定向:
https://www.mydomain.com/old_url/whatever
要:
https://www.mydomain.com/new_url/whatever
更新
如果不复制URI的其余部分(“what”),请使用:
RewriteCond %{REQUEST_URI} old_url.*
RewriteRule .* https://www.mydomain.com/new_url [R=301,QSA,NC]
答案 1 :(得分:0)
以下应该可以正常工作:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^old_url$ /new_url [L,R=301]
RewriteRule ^old_url/(.*) /new_url/$1 [L,R=301]