【问题标题】:how to specify a range in .htaccess file to redirect the url如何在 .htaccess 文件中指定范围以重定向 url
【发布时间】:2015-07-06 02:36:20
【问题描述】:

如果 ctatId 介于 45 到 600 之间,我会尝试重定向 url。如下所示

<pre> RewriteEngine on RewriteCond %{REQUEST_URI} Delhi/(.*)/[45-600] RewriteRule Delhi/(.*)/[45-600] pages/sub_category.php?city=Delhi&catId=$2 </pre>

但问题是它还会重定向catiId = 4 和每个以4 开头的catId 的URL,例如41,42 等 我认为指定范围时出了点问题

问候

【问题讨论】:

    标签: php apache .htaccess mod-rewrite redirect


    【解决方案1】:

    你必须使用正则表达式,这意味着你需要这样的东西:

    (4[5-9]|[5-9][0-9]|[1-6][0-9][0-9])
    

    即:

    • 从 4 开始,然后是 5-9
    • 或以 5-9 开头,然后是另一个数字
    • 或以 1-6 开头,然后是另外 2 个数字

    所以你只需要:

    RewriteRule Delhi/(.*)/(4[5-9]|[5-9][0-9]|[1-6][0-9][0-9]) pages/sub_category.php?city=Delhi&catId=$2
    

    【讨论】:

    • (4[5-9]|[5-9][0-9]|[1-5][0-9]{2}|600) 没有 601-699
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-01
    • 2015-08-19
    • 2018-02-13
    • 2018-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多