1
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !\.php$

RewriteRule ^(.*)/(.*)/(.*)$ $1.php?Action=$2&id=$3
RewriteRule ^(.*)/(.*)$ $1.php?Action=$2
RewriteRule ^(.*)$ $1.php

Here is my .htaccess. However only the first RewriteRule works. If I comment out other rules, the others left work fine, but they don't work together. What I want is the clean URL with multiple parameters.

I don't have any clue of this problem. I Googled a lot and all the information I've found says the same as my code.

2 Answers 2

1

You need to chain your RewriteRules using the C flag, as explained on the ServerFault page Everything You Ever Wanted to Know about Mod_Rewrite Rules but Were Afraid to Ask?

In your case, this would do:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !\.php$

RewriteRule ^(.*)/(.*)/(.*)$ $1.php?Action=$2&id=$3 [C]
RewriteRule ^(.*)/(.*)$ $1.php?Action=$2 [C]
RewriteRule ^(.*)$ $1.php
4
  • Thanks... but Still can't work out with C flag Aug 9, 2013 at 16:06
  • Hi. finally it's working with flag [L].... thanks anyways. .htaccess is always headache, isn't it? Aug 10, 2013 at 5:25
  • Hi, good to hear you got it working. Please answer your own question by posting the correct .htaccess, so others can learn from your situation. Aug 10, 2013 at 7:24
  • Options -MultiViews RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !\.php$ RewriteRule ^(.*)/(.*)/(.*)$ /api/$1.php?Action=$2&id=$3 [L] RewriteRule ^(.*)/(.*)$ /api/$1.php?Action=$2 [L] Aug 10, 2013 at 12:41
0
Options -MultiViews 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !\.php$ 
RewriteRule ^(.*)/(.*)/(.*)$ /api/$1.php?Action=$2&id=$3 [L] 
RewriteRule ^(.*)/(.*)$ /api/$1.php?Action=$2 [L]

With [L] flag, my htaccess started working fine.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .