【问题标题】:htaccess 301 redirect of matching string to another domain urlhtaccess 301 将匹配字符串重定向到另一个域 url
【发布时间】:2013-09-01 02:29:18
【问题描述】:

我正在尝试将域 a 的 url 重定向到域 b,其中重定向是为了适应域 b 的最佳可能 url

例如,要进行 301 重定向的域 A。

http://www.abc.com/blog/
http://www.abc.com/old-games?view=pages&layout=sell

博客旁边有很多pga,旧游戏等下有很多页面作为子url。

域 B

http://www.xyz.com/index.php?option=com_blog&view=entry&Itemid=5
http://www.xyz.com/index.php?option=com_forms&view=pages&layout=sellgames&Itemid=10

已尝试以下 htaccess 重定向条件

RewriteCond %{REQUEST_URI} ^.*/blog.*$
RewriteRule .*   http://www.xyz.com/index.php?option=com_blog&view=entry&Itemid=5 [R=301,L]

RewriteCond %{REQUEST_URI} ^.*/old-games.*$
RewriteRule .*  http://www.xyz.com/index.php?option=com_forms&view=pages&layout=sellgames&Itemid=10 [R=301,L]

重定向发生在

 http://www.xyz.com/index.php as tested using http://htaccess.madewithlove.be/

请建议最好的方法,就好像上面遗漏了什么一样

谢谢

【问题讨论】:

    标签: php apache .htaccess redirect mod-rewrite


    【解决方案1】:

    用这个替换你的代码:

    RewriteRule ^blog(/|$) http://www.xyz.com/index.php?option=com_blog&view=entry&Itemid=5 [R=301,L,QSA,NC]
    
    RewriteRule ^old-games(/|$) http://www.xyz.com/index.php?option=com_forms&view=pages&layout=sellgames&Itemid=10 [R=301,L,NC,QSA]
    

    确保在其他浏览器中进行测试或清除浏览器缓存。

    【讨论】:

    • 非常感谢,但是我上面写的代码有问题吗?谢谢
    • 不客气,是的,您的代码中的问题主要与您使用的正则表达式有关。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-18
    • 1970-01-01
    • 1970-01-01
    • 2011-04-28
    • 2016-03-25
    • 1970-01-01
    相关资源
    最近更新 更多