使用URL参数ID号范围进行HTACCESS重定向 [英] HTACCESS redirect using URL parameter ID number range

查看:77
本文介绍了使用URL参数ID号范围进行HTACCESS重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有人能提供帮助,因为事实证明这很难解决.

I'm hoping someone can help as this is proving difficult to figure out.

我正在尝试通过HTACCESS重定向并mod_rewrite许多具有特定范围(从1到7603)内的URL参数ID值的页面.

I am trying to redirect via HTACCESS and mod_rewrite a number of pages that have a URL parameter ID value within a particular range (from 1 to 7603).

这是我到目前为止所拥有的:

Here is what I have so far:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} &?id=\b([1-9][0-9]{0,2}|[1-6][0-9]{3}|7[0-5][0-9]{2}|760[0-3])\b [NC]
RewriteRule ^example\.php$ http://www.website.com/? [R=301,L]
</IfModule>

如果有ID URL参数,它当前确实会重定向页面,但它会重定向任何ID号,而不仅限于指定范围内的ID号,例如即使不应该,它也会重定向ID = 10000.

It currently does redirect the page if there is an ID URL parameter, but it redirects any ID number, not just those within the specified range, e.g. it will redirect ID=10000 even though is shouldn't.

有人知道我做错了什么以及如何解决吗?

Does anyone know what I have done wrong and how I can fix it?

推荐答案

使用显示的示例,请尝试以下.在测试URL之前,请确保清除缓存.将检查查询字符串的条件,以确保id =之后的值在此处远远低于7603,其余重定向部分仅根据OP所示示例.

With your shown samples, could you please try following. Please make sure you clear your cache before testing your URLs. Conditions for query string will be checked to make sure values after id= are well under 7603 here, rest redirection part is as per OP's shown samples only.

RewriteEngine ON
RewriteCond %{QUERY_STRING} id=[0-6]?[0-9]?[0-9]?[0-9]?(?![0-9]+) [NC,OR]
RewriteCond %{QUERY_STRING} id=7?[0-5]?[0-9]?[0-9]?(?![0-9]+) [NC,OR]
RewriteCond %{QUERY_STRING} id=760[0-3]?(?![0-9]+) [NC]
RewriteRule ^example\.php/?$ http://www.website.com/? [R=301,L]

这篇关于使用URL参数ID号范围进行HTACCESS重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆