【问题标题】:htaccess redirect if url have speific word如果 url 有特定的单词,htaccess 重定向
【发布时间】:2016-04-21 13:20:52
【问题描述】:

我有一个在我的网站上生成的垃圾邮件 URL 列表。我想将这些网址重定向到主页。这些所有垃圾邮件 url 在 url 中都有销售或折扣字样。 http://www.example.com/7ukwjvo-ralph-lauren-big-sizes-sale 我想将此重定向到http://www.example.com

我尝试过 htaccess 重定向但没有成功

RewriteCond %{REQUEST_URI} /(sale|discount)/$
RewriteRule (.*) http://www.example.com/ [R=301,L]

请提供解决方案

【问题讨论】:

    标签: .htaccess redirect


    【解决方案1】:

    尝试:

    RewriteEngine on
    RewriteCond %{REQUEST_URI} (sale|discount)$ [NC]
    RewriteRule ^ http://www.example.com/ [R=301,L]
    

    因为/(sale|discount) 只有在单词在/ 之后才有效。
    而对于(sale|discount)/$,它仅在单词最后在/ 之前才有效。

    您可以简单地使用(不带RewriteCond):

    RewriteRule (sale|discount)$ http://www.example.com/ [NC,R=301,L]
    

    而且你可以删除$来测试连的话到另一个地方结束

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多