【问题标题】:Htaccess - 301 domain redirectionHtaccess - 301 域重定向
【发布时间】:2013-10-23 11:28:54
【问题描述】:

我想将我的旧域重定向到新域。实际上我的网站在 www_olddomain_pl/index.php 下,英文版在 www_olddomain_com/index_en.php 下

我想做什么?

olddomain_pl -> www_new_pl
www_olddomain_pl -> www_new_pl
odldomain_com -> www_new_com
www_olddomain_com -> www_new_com

并从索引重定向到没有索引。 我到底有什么?

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*)olddomain_pl(.*) [NC]
RewriteRule ^(.*)$ http://www_olddomain_pl/$1 [R=301,L]
RewriteRule ^index.php$ http://www_new_pl/ [R=301,L]

RewriteCond %{HTTP_HOST} ^(.*)olddomain_com(.*) [NC]
RewriteRule ^(.*)$ http://www_new_com/$1 [R=301,L]

我不知道该怎么办。

编辑: 还有一个: 实际上,我的网站有两个版本 - 波兰语和英语。 波兰语版本在 olddomain_pl/index.php 下 英文版在olddomain_pl/index_en.php下

我想要: new_pl 下的波兰语版本 new_com下英文版

所以我需要从不带 www 重定向到带 www 并从 index.php 或 index_en.php 重定向到不带。

【问题讨论】:

    标签: php .htaccess mod-rewrite redirect


    【解决方案1】:

    你可以使用这条规则:

    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index_en\.php [NC]
    RewriteRule ^ http://www.live-dent.com/ [R=301,L,NC]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php [NC]
    RewriteRule ^ / [R=301,L,NC]
    
    RewriteCond %{HTTP_HOST} live-dent\.pl$ [NC]
    RewriteRule ^ http://www.livedent.pl%{REQUEST_URI} [R=301,L]
    

    编辑:根据评论:

    RewriteCond %{HTTP_HOST} live-dent\.com\.pl$ [NC]
    RewriteRule ^ http://www.livedent.pl%{REQUEST_URI} [R=301,L]
    

    【讨论】:

    • 对不起,它不起作用...如果我写:olddomain_pl/something in otput Ivewww_olddomain/somethingsomething 有问题。还有一个:实际上我的网站有两个版本——波兰语和英语。波兰语版本在 olddomain_pl/index.php 英语版本在 olddomain_pl/index_en.php 我想要:波兰语版本在 new_pl 英语版本在 new_com 所以我需要从 whitout www 重定向到 whit www 和从 index.php 或 index_en.php 到没有那个。
    • 你的英文版在www.olddomain.com/index_en.php OR www.olddomain.pl/index_en.php?
    • 好的,在这种情况下,我建议的规则将起作用。确保上述规则是您 DOCUMENT_ROOT/.htaccess 中的第一条规则,并在新浏览器中进行测试以避免 301 缓存问题。
    • 好的,再次编辑,现在试试。也不要使用htaccess.madewithlove.be 进行测试,它不是很可靠。在您自己的服务器上进行测试。
    • 如果它变得太复杂,我请求打开一个新问题,其中包含所描述的所有场景,以便可以正确解决所有问题。
    猜你喜欢
    • 2017-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-30
    • 1970-01-01
    • 2013-08-10
    • 2012-09-23
    相关资源
    最近更新 更多