antalya
antalya

Reputation: 85

How to Clean Dynamic URL's with .htaccess

I have tried the following in htaccess but does not seem to work,

Options +FollowSymLinks +Indexes +MultiViews

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ $1.php?bid=$2&page=$3 [L]

By doing this,

http://www.turkish-property-world.com/antalya_apartment.php?bid=4&page=1

should be

http://www.turkish-property-world.com/antalya_apartment/4/1

Upvotes: 0

Views: 69

Answers (2)

Vahe Shadunts
Vahe Shadunts

Reputation: 1966

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)/(.*)/$ $1.php?bid=$2&page=$3 [L,QSA]
RewriteRule ^(.*)/(.*)/(.*)$ $1.php?bid=$2&page=$3 [L,QSA]

Upvotes: 1

anubhava
anubhava

Reputation: 785146

Your rule is correct but real problem is your use of MultiViews. Take it out using:

Options +FollowSymLinks +Indexes -MultiViews

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ $1.php?bid=$2&page=$3 [L,QSA]
  • Option MultiViews is used by Apache's content negotiation module that runs before mod_rewrite and and makes Apache server match extensions of files. So /file can be in URL but it will serve /file.php.

Upvotes: 1

Related Questions