【问题标题】:htaccess redirect for sub dmoain and folder fileshtaccess 重定向子域和文件夹文件
【发布时间】:2012-10-22 13:07:15
【问题描述】:

所以我们有一个开发站点,例如:test.domain.com/dev/filename.html 并且它已被 Google 索引,所以我需要将它们重定向到 www.newdomain.com/filename.html 而不仅仅是文件还有文件夹/文件之类的。

test.domain.com/dev/example/filename.html

或 www.newdomain.com/example/example/filename.html

www.newdomain.com/filename.html

注意,test 域上的 /dev/ 文件夹不能在重定向上推送?

有人对此有什么想法吗?

我试过了:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !test.domain.co.uk/dev/$ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [L,R=301]

经过一些测试后,它会重定向到http://www.newdomain.com/dev/page.html,我需要删除 /dev/ .....

还有一些其他的选择,同时到处寻找,但还没有满足要求。

提前致谢

【问题讨论】:

    标签: apache .htaccess


    【解决方案1】:

    你还需要 RewriteCond 所以试试:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^test.domain.com [NC]
    RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]
    

    【讨论】:

    • 我试过了,但是转到了 404 页面,可能是因为它也可能将 /dev/ 添加到新的 url?
    • 我刚刚使用了htaccess.madewithlove.be 并且仍然在新网址中包含 /dev/ 但我需要删除它...有什么想法吗?
    • 你应该把.htaccess文件放在这里/dev/.htaccess
    • 我也明白了,这个规则不符合,因为上面测试的时候有一个条件没有满足
    • 会不会是 RewriteBase / 导致了问题?我在网站上的回答与我上面的答案完全相同,而且效果很好。我也从 sub.domain.com/dir 重定向 另请注意,我使用 ^test.domain.com NOT !test.domain.co.uk/dev/$
    猜你喜欢
    • 2011-10-14
    • 1970-01-01
    • 1970-01-01
    • 2012-09-17
    • 2017-07-04
    • 2014-12-03
    • 2013-11-08
    • 1970-01-01
    • 2012-11-23
    相关资源
    最近更新 更多