【问题标题】:redirecting unmatched pattern to another page using redirectmatch使用redirectmatch将不匹配的模式重定向到另一个页面
【发布时间】:2014-04-02 11:59:59
【问题描述】:

如果网址是这样的

   http://samplexxxx.com/some keywords/  it has to redirect to                                 

   http://samplexxxx.com/ap/search.php?searchterm=$1

因为我是这样写的

  RedirectMatch 301 ^/([^/]*)/ http://samplexxxx .com/ap/search.php?searchterm=$1  

     it was working fine

但是这里匹配的关键字不应该是 ap 即

                       http://samplexxxx.com/ap/

所以这里的重定向应该不是 ap 关键字那么我需要如何更改正则表达式匹配模式。

【问题讨论】:

  • RedirectMatch 301 ^/((?!ap/)[^/]+)/ samplexxxx .com/ap/search.php?searchterm=$1 当我使用其他目录时,例如@ 987654322@.com/images/image1.jpg,samplexxxx.com/adimages/adimage1.jpg url 也被重定向到搜索页面,因此将其更改为在多个表达式中检查负前瞻,如 RedirectMatch 301 ^/((?!ap |adimages|images|tamil/)[^/]*)/everydaypopcorn.com/ap/search.php?searchterm=$1 那么它就可以正常工作了。

标签: regex .htaccess redirect


【解决方案1】:

您可以在您的正则表达式中使用负前瞻:

RedirectMatch 301 ^/((?!ap/)[^/]+)/ http://samplexxxx .com/ap/search.php?searchterm=$1  

【讨论】:

  • 它正在工作,但我的网站中有另一种 url 格式,即sample.com/adimages/indexcenterad1.jpg 这也重定向到这里重定向应该只发生在exeminds.com/some 关键字以外的 ap/
  • 没有收到您的评论。您写道您想排除/ap/,这就是答案的作用。如果您想更改要求,请编辑您的问题并提供更多示例。
猜你喜欢
  • 1970-01-01
  • 2013-08-17
  • 2022-06-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-05
  • 1970-01-01
相关资源
最近更新 更多