应该是一个简单的301重定向

时间:2015-02-08 05:19:38

标签: apache .htaccess mod-rewrite redirect http-status-code-301

我认为应该很简单就是不行。

我已切换域名

旧网址示例: digital.photorecommendations.com/recs/2015/01/big-zoom-field-review /

新网址示例: photorec.tv/2015/01/big-zoom-field-review /

真的只是切换域并从URL中删除recs文件夹

使用http://htaccess.madewithlove.be/测试并输出正确的网址



Options +FollowSymlinks
RewriteEngine on
RewriteBase /recs
RewriteCond %{HTTP_HOST} !^www\.digital.photorecommendations\.com$ [NC]
RewriteRule ^recs(.*) http://photorec.tv/$1 [L,R=301]




当我将它放在htaccess文件中时,我在除主页之外的所有页面上都会出现404错误。 htaccess文件位于/ recs文件夹中。我也在digital.photorecommendations.com的根目录中尝试过它,我根本没有得到任何结果。

有什么建议吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

您在RewriteCond中错误地使用了否定,而正则表达式也需要修复。在/recs/.htaccess

中使用此规则
Options +FollowSymlinks
RewriteEngine on

RewriteCond %{HTTP_HOST} ^(www\.)?digital\.photorecommendations\.com$ [NC]
RewriteRule ^(index\.php)?$ http://photorec.tv/ [L,R=301,NC]

RewriteCond %{HTTP_HOST} ^(www\.)?digital\.photorecommendations\.com$ [NC]
RewriteRule ^(.+)$ http://photorec.tv/recs/$1 [L,R=301,NC,NE]
相关问题