Reputation: 441
I have a page that does two things:
When users click on this link: http://www.example.com/whatever_200/index.html/?id=4 it is actually processed by http://www.example.com/search/profile-condo.php?id=4
However, I also want to do the following for people in Brazil www.example.com/br/whatever_200/index.html/?id=4 www.example.com/br/search/profile-condo.php?id=4
The following works great for the english version:
addhandler x-httpd-php5 .html
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/index.html$ /search/profile-condo.php?name=$1&%{QUERY_STRING} [L,QSA]
But when I add
RewriteRule ^(.*)/br/^(.*)/index.html$ /br/search/profile-condo.php?name=$1&%{QUERY_STRING} [L,QSA]
It doesn't work.
What am I doing wrong?
Upvotes: 0
Views: 379
Reputation: 1075
There are three problems with your rules.
First of all the rule order. The first rule will match anything ending with /index.html
, and it will perform the redirect. It is (properly) flagged as the final rule (the L
flag). Because of that, the second rule will never be executed. If you add add the br
rule before the general rule, it will be tested first, and if it matches, the redirect will occur.
The second problem is the regular expression on your second rule. It contains a circumflex ^
halfway the expression. The circumflex means start of string, which obviously never occurs in the middle of the string. Removing the circumflex will fix that.
A third issue is that you're allowing characters before the /br/
part of your url (by having (.*)
in your expression. According to your description, you do not actually need this.
Summarizing:
addhandler x-httpd-php5 .html
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/br/(.*)/index.html$ /br/search/profile-condo.php?name=$1&%{QUERY_STRING} [L,QSA]
RewriteRule ^(.*)/index.html$ /search/profile-condo.php?name=$1&%{QUERY_STRING} [L,QSA]
Upvotes: 1