Different htaccess rewrite rules depending on the $ _GET parameter

Is there a way to make different rewrite rules in .htacessif some parameter was accepted GET?

For example, if the query string:

htttp://domain.com/?debug=1what .htaccessshould look like this:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

If the query string is not debug=1, than:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule !\.(js|ico|gif|jpg|png|css|html|swf|flv|xml)$ index.php?$1 [QSA,L]
+4
source share
2 answers

You can use RewriteCondas follows:

RewriteEngine on

# ?debug=1 is present
RewriteCond %{QUERY_STRING} (^|&)debug=1\b [NC]
RewriteRule (.*) app/webroot/$1 [L]

# ?debug=1 is not present
RewriteCond %{QUERY_STRING} !(^|&)debug=1\b [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l    
RewriteRule !\.(js|ico|gif|jpg|png|css|html|swf|flv|xml)$ index.php?$1 [QSA,L]
+3
source

You want to match the query string in RewriteCond:

RewriteCond %{QUERY_STRING}     ^debug=1$     [NC]
RewriteRule    (.*) app/webroot/$1 [L]

See docs or this example for more information .

+2
source

Source: https://habr.com/ru/post/1606556/


All Articles