Search code examples
regexapache.htaccesshttp-redirecthttp-status-code-301

redirecting url with parameters to same url without parameters


Using the file .htaccess, I am trying to redirect urls like this:

http://www.mysite.com/a-page/?fp=123&sp=456&tp=789

to:

http://www.mysite.com/a-page/

so basically redirecting url not caring about params values to the same url without any param.

I have used RewriteCond/RewriteRule, Redirect and RedirectMatch but without any luck.

My latest try was:

 RewriteCond %{QUERY_STRING} ^.+$
 RewriteRule ^a-page/$ http://www.mysite.com/a-page/? [L,R=301]

Any suggestion?


Solution

  • Well I have found a solution:

    RewriteCond %{QUERY_STRING} . [NC]
    RewriteCond %{REQUEST_URI} /a-page/
    RewriteRule ^ a-page/? [L,R=301]