.htaccess passing domain name

Tag: .htaccess Author: husj1975 Date: 2009-11-15

I am trying to Rewrite path in .htaccess

=-=-=-=-=-EDIT=-=-=

Hi I may not have expressed my problem clearly. So here's a live example of my problem.

"http://fames.in/site/bollywoodhungama.com" - works fine
"http://fames.in/site/bollywoodhungama.com/2" - error

The format of the url is:

http://fames.in/site/(site name)/(page number)

I use the following codes in .htaccess

RewriteRule ^site/(.*)$ sitelist.php?q=$1&page=1
RewriteRule ^site/(.*)/([0-9]+)$ sitelist.php?q=$1&page=$2

the first line works fine. In the second line of the code htaccess passess the whole parameters to 'q'. taking above url it is passed as "/sitelist.php?q=bollywoodhungama.com/2" . I need it to pass the 'q' and 'page' separately. Like "/sitelist.php?q=bollywoodhungama.com&page=2"

So for the example given 'domain.com' you show how it goes wrong, but also state, .com domain work. So can you give an example of a "bad" domain.
Hi, plz have a look at my question again. I have edited it for better understandability.
thanks for the update

Best Answer

The problem is that the first rule is always matching. The .* is greedy so the /2 is part of the match. What you need is the change the match to 'anything but slash' like so:

RewriteRule ^site/([^/]*)$ sitelist.php?q=$1&page=1

So the second domain will fail to match, and then the second rule will match.

Not sue if you need more rules applied after this rule of not, but you may want to add 'last rule flag' [L] to the end of you rule.

comments:

Hi Simeon, Adding [^/] and an [L] worked perfect for me. Thank You