Search code examples
.htaccessmod-rewritequery-stringqsa

htaccess query string with QSA


I am trying to set common rule in htaccess for removing .php extension and links using different query strings like

domainname.com/welcome.php?user=normal&type=free&uid=100
domainname.com/welcome.php?user=normal
domainname.com/welcome.php?log=new&theme=red

And expected links like

domainname.com/welcome?user=normal&type=free&uid=100
domainname.com/welcome?user=normal
domainname.com/welcome?log=new&theme=red

Rule set in htaccess file like:

RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^(.*)/welcome/$ $1/welcome.php? [QSA,NC,L]

But some how not working. Am I doing something wrong.


Solution

  • Try this in the .htaccess file at root directory:

    Options +FollowSymlinks -MultiViews
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI}  !welcome\.php [NC]
    RewriteRule ^welcome/?  /welcome.php      [NC,L]
    

    The query string will be passed automatically.