Toni Rovira
Toni Rovira

Reputation: 25

.htaccess rewrite rule condition doesn't work

I'm trying to do a rewrite rule but is not possible to me to find the correct expression. I've been searching in different kind of regular expression validators and they say that the expression works.

My .htaccess looks as follows:

Options +FollowSymlinks -MultiViews -Indexes
DirectoryIndex index.php index.html index.htm
RewriteEngine on
RewriteBase /
RewriteRule ^index\.php(.+)=([a-zA-Z]+)&([a-z]+)=([a-zA-Z]+)&([a-z]+)=([a-zA-Z]+)&([a-z]+)=(.*)$ /$3+$5+$7 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

The example URI is: http://www.example.com/index.php?r=site/action&param1=value1.

Upvotes: 0

Views: 80

Answers (1)

Jon Lin
Jon Lin

Reputation: 143856

You can't match against the query string in a rewrite rule, you need to either use the %{QUERY_STRING} or %{THE_REQUEST} variables.

Although it's entirely unclear what you're trying to do, try something like this:

Options +FollowSymlinks -MultiViews -Indexes
DirectoryIndex index.php index.html index.htm
RewriteEngine on
RewriteBase /

RewriteCond %{THE_REQUEST} \ /+index\.php\?(.+)=([a-zA-Z]+)&([a-z]+)=([a-zA-Z]+)&([a-z]+)=([a-zA-Z]+)&([a-z]+)=(.*)
RewriteRule ^ /%3+%5+%7 [L]

Upvotes: 1

Related Questions