Default query string in .htaccess

A bit of a weird question, but I would like the query string to be asked for all of my urls. If the parameter is not set (or empty) then I would like to redirect to include the default.

For example:

example.com would need to requrect to example.com?param=a

example.com?param would also need to redirect to example.com?param=a

      

If the parameter is set and is part of a list of known values, it should be executed as usual:

example.com?param=(a|b|c|d) would go to the respective page a,b,c or d

      

Some of the pages on the site use different sorting and pagination options, so rules cannot assume that this is the only query string.

I tried a couple of things but kept getting stuck in the redirect loop. This tries to set the default parameter:

RewriteCond %{QUERY_STRING} !(^|&)param=(a|b|c|d)($|&)
RewriteRule ^(.*)$ /index.php?rq=$1&param=a [L,QSA]

      

Basic rule of CMS rewrite:

RewriteCond %{REQUEST_URI} !^\/*(index\.php|blog|admin\/assets|site\/assets|robots.txt|sitemap(|\-[0-9]+)\.xml|products.xml|favicon\.ico)
RewriteRule ^(.*)$ /index.php?rq=$1 [L,QSA]

      

Any help would be great!

+1


source to share


1 answer


RewriteCond %{QUERY_STRING} !(^|&)param=(a|b|c|d)($|&)
RewriteCond %{REQUEST_URI} !^\/*(index\.php|blog|admin\/assets|site\/assets|robots.txt|sitemap(|\-[0-9]+)\.xml|products.xml|favicon\.ico)
RewriteRule ^(.*)$ $1?%{QUERY_STRING}&param=a [L]

RewriteCond %{REQUEST_URI} !^\/*(index\.php|blog|admin\/assets|site\/assets|robots.txt|sitemap(|\-[0-9]+)\.xml|products.xml|favicon\.ico)
RewriteRule ^(.*)$ /index.php?rq=$1 [L,QSA]

      



+1


source







All Articles