Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.
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.

share|improve this question

2 Answers 2

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
share|improve this answer
    
Thanks... but Still can't work out with C flag –  user1942626 Aug 9 '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 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. –  Luc van Donkersgoed Aug 10 '13 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] –  user1942626 Aug 10 '13 at 12:41
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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.