How to remove variables from a URL with htaccess


When accessing URLs such as the following:



  • I want the search parameters to be removed:


    I have many URLs of that type, what varies is the code that is at the end. I do not need those parameters, since those variables do not exist, it will not affect that you eliminate them. The same thing appears to the user, whether or not the parameters are present.

    How can I do that?

    asked by Erick Estevez 12.03.2018 в 19:09

    2 answers


    If you access page/### (with ### any number of digits) with search parameters, this rule redirects to the same URL but without the parameters:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{QUERY_STRING} .
    RewriteRule ^(page/\d+/?)$ $1 [NC,QSD,R=302,L]
    • The flag [QSD] ( query string discard ) just discards the parameters.
    • Whenever you are implementing a redirection, you must first do all the tests with a 302. Only if you are very sure that it works, and that they are not going to change in the future, then you could change it to a 301. Not before, because it is dangerous: 301 redirects are heavily frisked.
    answered by 13.03.2018 / 00:06

    If I understand you correctly, what you want is to eliminate the parameters of the url. You understand therefore that these variables will no longer be accessible. Your .htaccess could be something like this:

    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^/page/([0-9])/(.*)$
    RewriteRule ^(.*)$1 [R=302,NC]
    answered by 12.03.2018 в 19:52