Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Yet another Mod_ReWrite issue posting

9:17 pm on Apr 27, 2006 (gmt 0)

5+ Year Member

Yes I too am posting about a mod-rewrite issue. the following is my .htaccess file. What is happening is that the variables are not getting passed to the appropriate pages unless they are the last two lines in .htaccess file.

How do I get it to allow the variable to be passed on the first four lines of rules?




Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^listings/([^/]+)/([^./]+)/?$ /listings.php?city_id=$1&listing_id=$2 [L]
RewriteRule ^listings/([^./]+)/?$ /listings.php?city_id=$1 [L]
RewriteRule ^lots/([^/]+)/([^./]+)/?$ /lots.php?city_id=$1&lot_id=$2 [L]
RewriteRule ^lots/([^./]+)/?$ /lots.php?city_id=$1 [L]
RewriteRule ^subdivisions/([^/]+)/([^./]+)/?$ /subs.php?city_id=$1&sub_id=$2 [L]
RewriteRule ^subdivisions/([^./]+)/?$ /subs.php?city_id=$1 [L]

10:02 pm on Apr 27, 2006 (gmt 0)

10+ Year Member

Can you give an example of the URL (without your domain name of course) that is represented by the left-hand side of your rewrite?

I have absolutely no problems with something like this:


Being turned into


by using:

RewriteRule ^(.*)/(.*)/catid(.*) /script.cgi?STUFF=$1&THING=$2&CAT=$3 [L]

It looks like you may be trying to do a similar thing but are using ([^/]+) instead of (.*).


11:04 pm on Apr 27, 2006 (gmt 0)

5+ Year Member





just seems that on the last one the city_id works, but the first two sets don't

11:45 pm on Apr 27, 2006 (gmt 0)

10+ Year Member

RewriteRule ^lots/([^/]+)/([^./]+)/?$ /lots.php?city_id=$1&lot_id=$2 [L]

I do notice you have a . in the last one and not in the first one. ([^/]+) vs ([^./]+) . I believe that "." is "any character", so by leaving it out, you may be breaking your rule. You could also just try:

RewriteRule ^listings/(.*)/(.*)/?$ /listings.php?city_id=$1&listing_id=$2 [L]

I'm no mod_rewrite guru, but I think the above would work. Or maybe it's just the missing ".".


11:59 pm on Apr 27, 2006 (gmt 0)

5+ Year Member

its still making its error, even with changing it as you have.

when I go to /listings/city/number the page displays none of the $_GET variables so they are not getting passed as they should be. Same with /lots/city/number, but yet with subdivision/city/number they get passed.

in each file, listings.php, lots.php and subs.php I just have an echo statement to show each of the variables from the query string.

5:22 pm on Apr 28, 2006 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

I don't see anything wrong with the original code, although as JollyK has pointed out, you don't need the "." in the grouped excluded characters.

Using a specific pattern like ([^/]+) is much more efficient than using (.*) when more than one sub-pattern is used. (See this post [webmasterworld.com] for details.)

Have you tried requesting any of the URLs that don't work, but with a trailing slash? Does that make any difference?