Jon
Jon

Reputation: 134

How to do .htaccess 301 redirect with # in url

I need to write 301 redirection code in htaccess. What I have tried.

RewriteRule ^old-url-shoes/$  new-url-shoes-abc/#div-id-shoes [R=301,NC,L] 

This code is creating this url

new-url-shoes-abc/%23div-id-shoes

It is replacing '#' with '%23'.

Please suggest a solution.

Upvotes: 1

Views: 59

Answers (1)

RavinderSingh13
RavinderSingh13

Reputation: 133518

Could you please try following once, written and tested with shown samples. Please do clear your browser cache before testing your URLs.

RewriteRule ^old-url-shoes/$  new-url-shoes-abc/#div-id-shoes [R=301,NC,NE,L]

From documentation:

NE|noescape By default, special characters, such as & and ?, for example, will be converted to their hexcode equivalent. Using the [NE] flag prevents that from happening.

Also as an additional suggestion use ^old-url-shoes/?$ ? so it will cover cases of either url is ending with slash or not in Rules.

Upvotes: 2

Related Questions