Passing variables through htaccess using rewrite rule

I am trying to rewrite the following

http://example.com/somefile?variable=somevariable

to

index.php?processurl=/somefile?variable=somevariable

I understand that I need to use [QSA] to pass variables, so I wrote the following in my htaccess:

RewriteEngine On
RewriteBase /
RewriteRule ^(.*) index.php?processurl=/$1 [QSA]

However, this RewriteRule does not seem to pass a variable. All I get is index.php? Processurl = / somefile

+4
source share
2 answers

Problem

The problem is understanding the flag QSA. What this does is add the original query string to the redirected URL. This is useful in some cases when you want to add another parameter (or more than one) to the query string.


Example

Given the url:

http://example.com/?var1=somevalue

:

RewriteRule . /?var2=thisvalue
RewriteRule . /?var2=thisvalue [`QSA`]

:

Rule 1 > http://example.com/?var2=thisvalue
Rule 2 > http://example.com/?var2=thisvalue&var1=somevalue

, , ; ...

- , - ...

%{QUERY_STRING}:

RewriteEngine On
RewriteBase /
RewriteRule ^(.*) index.php?processurl=/$1?%{QUERY_STRING}

, :

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

URL-.

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?processurl=/$1?%{QUERY_STRING}
+1

:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?processurl=/$1 [QSA,L]
+1

All Articles