Mobile app version of vmapp.org
Login or Join
Chiappetta492

: Remove query string from 301 redirect URL I'm having some trouble with redirects and I haven't been able to get this to work. I want to make the following http://www.example.com/seasonal/christmas?p=15

@Chiappetta492

Posted in: #301Redirect #Htaccess

I'm having some trouble with redirects and I haven't been able to get this to work. I want to make the following
www.example.com/seasonal/christmas?p=15

redirect to
www.example.com/holiday-decor/christmas.html

I was wondering if someone could help me with the rewrite rule so the query string doesn't appear in the redirected URL. I'm using .htaccess with a Magento platform site.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Chiappetta492

2 Comments

Sorted by latest first Latest Oldest Best

 

@Ann8826881

By default the query string on the requested URL is appended to the rewritten/redirected URL. The easiest way to remove the query string from the redirected URL is to simply append a ? at the end of the RewriteRule substitution. This essentially writes a blank query string (the ? does not actually become part of the rewritten URL).

So, from your example:

RewriteEngine On
RewriteCond %{QUERY_STRING} =p=15
RewriteRule ^seasonal/christmas$ /holiday-decor/christmas.html? [R=301,L]


The RewriteCond directive is required in order to match the query string part of the requested URL. The URL matched against the RewriteRule pattern does not include the query string. The = prefix on the CondPattern =p=15 indicates a a literal "string" match, so it matches p=15 exactly.

10% popularity Vote Up Vote Down


 

@Murray155

Try adding this to your .htaccess in the document root:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)&?start=0(.*)$
RewriteRule ^/?products.php$ /products.php?%1%2 [R=301,NE]

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme