views:

70

answers:

4

I am trying to write a rule which says

xyz.com/hotels_in_someplace will direct to xyz.com/test.php?place=someplace

by using the following in my htaccess

RewriteEngine On
RewriteBase /

RewriteRule ^hotels_in_([a-z]+)$ test.php?place=$1 [L]

but its not working and I cant figure out why, I am running a wamp server as a dev. when i tried to run xyz.com/test.php?place=someplace (without the htaccess in the directory) it works but I suspect there's something my rule which is wrong.

additional: whoops....my dumb ass mistake, mod_rewrite wasnt enabled...

A: 

Update: I didn't notice the RewriteBase in the question before so my point about the leading slash is null. However the RewriteRule does work on my machine.


Try:

RewriteRule ^hotels_in_([a-z]+)$ /test.php?place=$1 [L]

The path to test.php needs the leading slash. The way you are doing the rewrite you will be redirected to xyz.com/path/to/web/docs/on/machine/test.php and thats not what you want. :)

Also if you are you including a trailing slash in your test.

The above rule will not match xyz.com/hotels_in_someplace/.

To match the leading slash this should work:

RewriteRule ^hotels_in_([a-z]+)/?$ /test.php?place=$1 [L]
MitMaro
+1  A: 

Try it without the end-line anchor ($)

RewriteRule ^/hotels_in_([a-z]+) /test.php?place=$1 [L]

Also, did you allow the .htaccess files to be parsed?

Tarnschaf
A: 

Your example works fine for me. Might want to make a few little adjustments (see my example, which captures uppercase letters, hyphens and underscores (for hotels in countries with more than one word (united-states, united_states)) and a trailing forward slash).

RewriteRule ^hotels_in_([A-Za-z_-]*)(/?)$ /test.php?place=$1

Hope that helps.

Gav
A: 

mod_rewrite wasnt enabled...doh...I hate mondays

Joe
Then close/delete your question please.
Gumbo
will do, it says I need to wait another 29 hours before doing so
Joe