.htaccess RewriteRule


#1

Hi,

I am trying to make the following URL

http://www.mywebsite.com/gallery/1597/Hollywood-Movies-(2009).php

to point…

http://www.mywebsite.com/gallery/index.php?cat=1597

I tried this…

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^gallery/([0-9])/(.*)$ /gallery/index.php?cat=$1 [L]

and saved the .htaccess file in website root. Please help me with correct rewrite rule.

Thanks
Sudipto


#2

http://www.mywebsite.com/gallery/1597/Hollywood-Movies-(2009).php

The trick is your ([0-9]) is looking for http://www.mywebsite.com/gallery/1/Hollywood-Movies-(2009).php

So by saying ([0-9]{4}), we say it’s a 4 digit number.


#3

And assuming your gallery started with [font=courier]1[/font] and may grow beyond [font=courier]9999[/font], you could either put a range of acceptable digit places:

or accept any number of digits in that position as long as there is at least one: