Trell
Trell

Reputation: 27

mod_rewrite rule not working as it should

I've used this particular mod_rewrite rule in several other places and it works perfectly as expected. However, it isn't working here, and for the life of me I cannot see why.

The setup is as follows:

www.site.com/villas-in-florida/

The .htaccess file is in the directory above, and has the following in it:

Options +FollowSymLinks
Options +Indexes
RewriteEngine On

RewriteRule ^([^/]+)-([^/]+)-([^/]+)-([^/]+)$ show-villa.php?id=$1&name=$2&location=$3&state=$4 [L]

This should convert the following:

http://www.site.com/villas-in-florida/show-villa.php?id=1&name=calabay-parc&location=davenport&state=florida

Into:

http://www.site.com/villas-in-florida/1-calabay-parc-davenport-florida

But it doesn't, and I'm tearing my actual hair out right now. Any and all tips would be gratefully appreciated, thanks!

Upvotes: 0

Views: 96

Answers (1)

ThinkingMonkey
ThinkingMonkey

Reputation: 12727

It wont convert:

http://www.site.com/villas-in-florida/show-villa.php?id=1&name=calabay-parc&location=davenport&state=florida

Into:

http://www.site.com/villas-in-florida/1-calabay-parc-davenport-florida

Its the other way around. i.e

It will rewrite (not convert):

http://www.site.com/villas-in-florida/1-calabay-parc-davenport-florida

Into:

http://www.site.com/villas-in-florida/show-villa.php?id=1&name=calabay-parc&location=davenport&state=florida

You have to use URLs like http://www.site.com/villas-in-florida/1-calabay-parc-davenport-florida in your h refs not http://www.site.com/villas-in-florida/show-villa.php?id=1&name=calabay-parc&location=davenport&state=florida. The rewritten URL will not get reflected in the browser.

Also there is a small mistake in the rewriterule.

Options +FollowSymLinks
Options +Indexes
RewriteEngine On

RewriteRule ^([^/]+)-([^/]+)-([^/]+)-([^/]+)-([^/]+)$ show-villa.php?id=$1&name=$2-$3&location=$4&state=$5 [L]

Upvotes: 1

Related Questions