Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I had a small bit of code that would redirect pages accessed from my own domain to their hash addresses, like so: => 

This was the code:

<IfModule mod_rewrite.c>
 # Redirect requests to ajax pages the their hashes
 RewriteCond $1 !=index [NC]
 RewriteCond %{HTTP_REFERER} !^$
 RewriteCond %{HTTP_REFERER} !^https?://(www\.)?example\.com/ [NC]
 RewriteRule ^([a-zA-Z0-9\-_]+)\.html?$ /#$1 [NE,R]

This would work great, now I'm wondering can I get it to redirect pages like =>!/stationary 

Hacking the above code didn't work. Any help would be appreciated!
Thank you!

share|improve this question

migrated from May 18 '12 at 15:08

This question came from our site for professional and enthusiast programmers.

.htaccess questions aren't allowed on stackoverflow anymore? Then why do we have related tags, puzzled. – Mohammad May 15 '12 at 19:38
I have no idea what casperOne was thinking. It seems to be a perfectly cromulent question to me. – abelenky May 15 '12 at 19:39
.htaccess questions go on ServerFault. They are off topic for Stack Overflow. – casperOne May 18 '12 at 15:07
@casperOne: .htaccess questions are on-topic for – w3d Jan 11 '14 at 15:01

I'm not sure what you think a "hash address" is; a URL with a hash mark in it refers to an anchor on the page in question, and is not a resource in and of itself.

Refer to RFC 2616 for details.

Regardless, as to your question: you will have to repeat the entire Rule, including all RewriteConds, to match something else.

RewriteCond $1 ! \.html?$ [NC]
RewriteRule ^([a-zA-Z0-9_-]+)$ /#!/$1 [NE,R]

Also, move the "-" to the end of the collection so you don't have to escape it.

Oh, and get rid of the IfModule; you would know if it's loaded or not.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.