0

我有一个已更改域的网站。我有 4 个特定页面需要重定向到新域上的新等效页面。除此之外,我希望整个域重定向到新域。

这是我的代码:

Options +FollowSymLinks
RewriteEngine on

RewriteBase /

# Redirect individual pages.
RewriteRule http://olddomain.net/subdirectory/subpage1/$ https://www.newdomain.com/newsub/newpage1/ [R=301,L]

RewriteRule http://olddomain.net/subdirectory/subpage2/$ https://www.newdomain.com/newsub/newpage2/ [R=301,L]

RewriteRule http://olddomain.net/subdirectory/subpage3/$ https://www.newdomain.com/newsub/newpage3/ [R=301,L]

RewriteRule http://olddomain.net/subdirectory/subpage4/$ https://www.newdomain.com/newsub/newpage4/ [R=301,L]

RewriteRule (.*) http://www.newdomain.com/ [R=301,L] 

我也尝试过像这样编写 RewriteRules,但它具有相同的效果:

RewriteRule ^/subdirectory/subpage1/$ https://www.newdomain.com/newsub/newpage1/ [R=301,L]

这似乎只执行了最后一行,即它总是重定向到http://www.newdomain.com/,无论输入了什么 olddomain.net URL。如何让各个 URL 重定向?

已解决:这是我最终使用的:

RewriteEngine On

RewriteCond %{REQUEST_URI} ^/subdirectory/subpage1/$
RewriteRule ^.*$ https://www.newdomain.com/newsub/subpage1/ [R=301,L]

RewriteCond %{REQUEST_URI} ^/subdirectory/subpage2/$
RewriteRule ^.*$ https://www.newdomain.com/newsub/subpage2/ [R=301,L]

RewriteCond %{REQUEST_URI} ^/subdirectory/subpage3/$
RewriteRule ^.*$ https://www.newdomain.com/newsub/subpage3/ [R=301,L]

RewriteCond %{REQUEST_URI} ^/subdirectory/subpage4/$
RewriteRule ^.*$ https://www.newdomain.com/newsub/subpage4/ [R=301,L]

Redirect 301 / http://www.newdomain.com/
4

1 回答 1

0

RewriteRule 在 Path not full Uri 上运行,您尝试的第二种方法工作正常,只需删除前导斜杠:

RewriteRule ^subdirectory/subpage1/?$ https://www.newdomain.com/newsub/newpage1/ [R=301,L]

RewriteRule ^subdirectory/subpage2/?$ https://www.newdomain.com/newsub/newpage2/ [R=301,L]

RewriteRule ^subdirectory/subpage3/?$ https://www.newdomain.com/newsub/newpage3/ [R=301,L]

RewriteRule ^subdirectory/subpage4/?$ https://www.newdomain.com/newsub/newpage4/ [R=301,L]

RewriteRule (.*) http://www.newdomain.com/ [R=301,L] 
于 2013-06-27T20:21:08.453 回答