0

I'm trying to do some basic point to point redirects using 301 redirect 301 with a .htaccess.

All is going well but there is one type of URL that is not happy.

I'm trying to go from:

http://www.greenshorticulture.co.uk/details.asp?productid=802&subcat=189&cat=182

To:

https://greenshydro.co.uk/hydroponics

I'm using:

Redirect 301 /details.asp?productid=802&subcat=189&cat=182  
https://greenshydro.co.uk/hydroponics

But when I run the check on it I end up with:

https://greenshydro.co.ukdetails.asp/?productid=647&subcat=347&cat=198

Other redirects without the question mark in them are working fine, just this type is failing.

The pages that I am trying to redirect to are old product pages - I need to do individual links to avoid soft 404's.

5
  • 1
    From the Apache documentation for mod_alias (which supplies Redirect): "mod_alias is designed to handle simple URL manipulation tasks. For more complicated tasks such as manipulating the query string, use the tools provided by mod_rewrite." Jan 18, 2020 at 9:59
  • OK, so I found the answer in this link: link The code I needed was: RewriteEngine On RewriteCond %{QUERY_STRING} ^productid=802&subcat=189&cat=182$ [NC] RewriteRule ^details\.asp$ https://greenshydro.co.uk/hydroponics? [R=301,L] Strangely though this generates a 302, not a 301. Not really an issue as the page rank will be passed and the user will arrive at the right page, but would be good to know why it is 302 when I specify 301 in the code?
    – Tom Green
    Jan 20, 2020 at 1:26
  • Whilst the directive (redirect) you posted is not correct, it's also not the directive that is triggering the redirect you are seeing. One of your "other redirects" must be doing that (eg. using a Redirect directive and omitting the trailing slash after the target domain will do it).
    – MrWhite
    Jan 20, 2020 at 1:26
  • (You should also have been able to derive the correct redirect from the linked question above?) "Strangely though this generates a 302, not a 301" - If you are seeing a 302 then it suggests another directive is performing the redirect?! Are you sure the 302 is actually for that redirect and there isn't actually 2 separate redirects (in which case you have a conflict)?
    – MrWhite
    Jan 20, 2020 at 1:42
  • 1
    @MrWhite You are correct, there was indeed another directive at the top of the file that the hosting tech support had added and I had not seen. This was causing the 302 as 301 was not specified. However, I removed this directive and reverted back to using RewriteEngine On RewriteCond %{QUERY_STRING} ^productid=802&subcat=189&cat=182$ [NC] RewriteRule ^details\.asp$ https://greenshydro.co.uk/hydroponics? [R=301,L] - this gets the job done fine. Thanks for your help.
    – Tom Green
    Jan 20, 2020 at 1:56

0

Browse other questions tagged or ask your own question.