There is a URL:https://www.carpark.cc/contact_us.html#b
that I want to redirect to:
https://www.carparkpro.com/contact-us/#hk
My .htaccess code is:
RewriteCond %{HTTP_HOST} ^cn\.carpark\.cc$
RewriteRule ^contact_us/(.*)/? https://www.carparkpro.com/contact-us/#cn$ [NC,NE,R=301]
but it didn't work, pls tell me how to write the code, thanks
I suspect the actual URL that get's requested is https://www.carparkpro.com/contact-us
, not https://www.carparkpro.com/contact-us/
which explains why the rule does not get applied. Please understand that anchors (...#...
) are not part of the URL. A client will never send that anchor, but only the URL. So the server will never receive such an anchor.
I would suggest a slightly modified version of your rule:
RewriteCond %{HTTP_HOST} ^cn\.carpark\.cc$
RewriteRule ^/?contact_us/? https://www.carparkpro.com/contact-us/#cn$ [NC,R=301,L]