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.

slm
  • 7,355
  • 16
  • 54
  • 72
user1942626
  • 111
  • 1
  • 2

2 Answers2

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
  • Thanks... but Still can't work out with C flag – user1942626 Aug 09 '13 at 16:06
  • Hi. finally it's working with flag [L].... thanks anyways. .htaccess is always headache, isn't it? – user1942626 Aug 10 '13 at 05: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. – Luc van Donkersgoed Aug 10 '13 at 07: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] – user1942626 Aug 10 '13 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.

user1942626
  • 111
  • 1
  • 2