【问题标题】:Apache rewrite AND redirectApache 重写和重定向
【发布时间】:2014-11-27 20:28:47
【问题描述】:

我需要一些帮助来重写和重定向以及处理一些旧的重写代码。

在 .htaccess 中我有一些旧代码:

 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d

 RewriteRule ^Products[/]{0,1}$  /index.php?tabs=2 [L,QSA,NC]

因此,据我了解,这段旧代码正在重写页面,因此如果有人输入http://www.example.com/Products/,它会显示 index.php?tabs=2,但 URL 实际上会显示 http://www.example.com/Products/。但是,我想在这种情况下,并没有发生实际的重定向,所以两个页面是一起存在的?

所以,我现在需要做的是……我有这个新的工作页面:

 http://www.example.com/NewProducts.html?type=newest

如果有人输入:

 http://www.example.com/NewProducts/ 

我希望显示新的工作页面:

 http://www.example.com/NewProducts.html?type=newest 

但我希望这个 SEO 友好的 URL 显示在地址栏中:

 http://www.example.com/NewProducts/

我也希望它是一个重定向,而不仅仅是一个重写,以便 SEO 领域的所有内容都是正确的。

而且,如果有人输入旧网址:

 http://www.example.com/Products/  

我希望那个 301 重定向到新页面的新 SEO 友好 URL:

 http://www.example.com/NewProducts/ 

这是我尝试过的,但它不正确:

 RewriteRule ^Products[/]{0,1}$  NewProducts.html?type=newest [L,QSA,NC,R=301]
 RewriteRule ^ProductsNew[/]{0,1}$  NewProducts.html?type=newest [L,QSA,NC,R=301]

【问题讨论】:

    标签: apache .htaccess mod-rewrite redirect seo


    【解决方案1】:

    你可以使用这样的规则:

    Options -MultiViews
    RewriteEngine On
    
    RewriteRule ^Products/?$ /NewProducts/ [L,NC,R=301]
    RewriteRule ^NewProducts/?$ /NewProducts.html?type=newest [L,QSA,NC]
    

    【讨论】:

    • 效果很好。感谢您的帮助!
    猜你喜欢
    • 2017-11-21
    • 1970-01-01
    • 1970-01-01
    • 2014-11-03
    • 2012-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多