15

I want to redirect a URL containing a hash to another URL.

Example: example.com/#test should redirect to example.com/teste_page

Can this be done using the .htaccess file?

0

3 Answers 3

39

Yes it can be done, just use the No Escape flag... [NE,R,L]

Sign up to request clarification or add additional context in comments.

2 Comments

So what would the full rule be in HTACCESS? RewriteRule ^(.*)#(.*)$ /$1$2 [NE,R,L] ?
This is the right answer to the wrong question. With this you could convert 'example.com/teste_page' to 'example.com/#test' not the other way around
14

No, hashes are never sent to the server, they are in-page fragment identifiers, so only used by the browser. So you're .htaccess would never have access to the hash. You'd have to do some nifty redirects to get that info to your server.

Here are some ideas that might spark something:

http://forum.modrewrite.com/viewtopic.php?t=3912

1 Comment

You can only redirect from opposite direction, from example.com/teste_page to example.com/#test. Sending a header Location with url that contain a hash work.
0

This cannot be done with .htaccess - as far as the browser is concerned, the # and anything following it does not need to be sent to the server, as it's a link for the browser to resolve.

Here's a related question, as well as an example:

Note google thinks the request was: http://www.google.com/thisisa404?query=string#fragment

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.