: What is correct syntax for .htaccess 301 redirect of query based URL to new URL? I wish to set up some 301 redirects to new URLs and I am trying to do this with the redirect facility in
I wish to set up some 301 redirects to new URLs and I am trying to do this with the redirect facility in cPanel. For some reason the requests are not being processed correctly and I am guessing that this is because the old URLs are query based.
It looks like I will have to modify my .htaccess file manually and my question is: what is the correct syntax to use, based on the examples given below.
www.mydomain.com/products.asp?category=42 needs redirecting to www.mydomain.com/products/new-category.
More posts by @Phylliss660
1 Comments
Sorted by latest first Latest Oldest Best
cPanel will also not be able to determine whether you have other conflicting directives in your .htaccess file.
The RewriteRule pattern matches against the URL-path part of the URL so you will need to use a RewriteCond directive with the %{QUERY_STRING} variable.
RewriteCond %{QUERY_STRING} =category=42
RewriteRule ^products.asp /products/new-category? [R=301,L]
The = at the start of the RewriteCond pattern essentially performs an exact (string) match (if that is required).
The ? on the end of the RewriteRule substitution removes the querystring from the request, otherwise it will be passed through unchanged.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.