.htaccess RewriteRule country codes and URLs

I am using the following .htaccess code:

RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ca/(.+)$ /index.php?p=$1&c=ca [L,QSA] RewriteRule ^fr/(.+)$ /index.php?p=$1&c=fr [L,QSA] RewriteRule ^(.+)$ /index.php?p=$1 [L,QSA] 

To achieve the following effect:

 http://xyz.com/ca/test -> http://xyz.com/index.php?p=test&c=ca http://xyz.com/fr/test -> http://xyz.com/index.php?p=test&c=fr http://xyz.com/test -> http://xyz.com/index.php?p=test 

But this is a server error. Any ideas on how to fix this?

thanks

+4
source share
1 answer
Terms

RewriteCond only applies to a RewriteRule that immediately follows condition (s). In your last 2 rules there are no conditions for them, and the rules loop. Just add 2 conditions before the last 2 rules:

 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ca/(.+)$ /index.php?p=$1&c=ca [L,QSA] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^fr/(.+)$ /index.php?p=$1&c=fr [L,QSA] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)$ /index.php?p=$1 [L,QSA] 
+2
source

All Articles