Search code examples
apache.htaccesshttp-redirectmod-rewriteurl-rewriting

Remove query string from URL using .htaccess


I am trying to make the following redirection using .htaccess.

Redirect this:

http://www.example.com/[email protected]

To this:

http://www.example.com/index.php?something

So basically all I want is to remove @gmail.com from the query string whenever is presented while keeping everything else.

I tried the following:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)@gmail.com$
RewriteRule (.*) $1?%1%2? [R=permanent]

Unfortunately didn't work even after doing multiple tweaks. What is wrong?


Solution

  • With your shown samples/attempts, please try following. Please make sure to clear your browser cache before testing your URLs. Please make sure that htacces and index.php files are on root folder at same level.

    RewriteEngine ON
    ##Redirect rules to get index.php?something in browser here.
    RewriteCond %{THE_REQUEST} \s/(index\.php)\?([^@]*)@.*\s [NC]
    RewriteRule ^ /%1?%2 [R=301,L]