How to specify range in .htaccess file for url redirect
I am trying to redirect url if ctatId is something between 45 and 600. For example below
<pre>
RewriteEngine on
RewriteCond %{REQUEST_URI} Delhi/(.*)/[45-600]
RewriteRule Delhi/(.*)/[45-600] pages/sub_category.php?city=Delhi&catId=$2
</pre>
but the problem is that it also redirects the url for catiId = 4
and each catId
that starts with 4
, like 41,42
, etc. i think there is something wrong by specifying the range
respectfully
+3
source to share
1 answer
You have to use a regular expression, that means you need something like:
(4[5-9]|[5-9][0-9]|[1-6][0-9][0-9])
I.e:
- starts with 4, then 5-9
- or starts with 5-9 followed by another digit
- or starts with 1-6, then 2 more digits
So, you just need:
RewriteRule Delhi/(.*)/(4[5-9]|[5-9][0-9]|[1-6][0-9][0-9]) pages/sub_category.php?city=Delhi&catId=$2
+1
source to share