0

我似乎无法弄清楚如何 301 将旧 URL 重定向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。任何帮助是极大的赞赏。

4

2 回答 2

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 的其余部分(“whatever”),请使用:

RewriteCond %{REQUEST_URI} old_url.*
RewriteRule .* https://www.mydomain.com/new_url [R=301,QSA,NC]
于 2012-12-28T20:30:37.717 回答
0

以下应该可以正常工作:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^old_url$ /new_url [L,R=301]
RewriteRule ^old_url/(.*) /new_url/$1 [L,R=301]
于 2012-12-28T18:25:17.847 回答