Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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 would like to get the following apache-redirect working:

When someone surfs to mydomain.tld/contact, they should be redirected to mydomain.tld/#contact.

This is because I built a one-page-website with autoscrolling.

This is not working:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php#$1 - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]


share|improve this question
Your example is missing things you are asking for. E.g. RewriteRule ^index.php\/(.*)$ \#$1 – pduersteler Feb 6 '12 at 14:27
Thanks for your comments @pduersteler, but after changing my RewriteRule to RewriteRule ^index.php\/(.*)$ \#$1 it still won't work. – Bert Feb 6 '12 at 14:35
I see you updated your code, but you updated wrong. I think you need to read the docs: You are missing some things. – pduersteler Feb 6 '12 at 14:43
up vote 2 down vote accepted

I'm not quite following what your existing rules are going for, but I believe you want something like this:

RewriteBase /
# Send a request for / (or /#something) to /index.php:
RewriteRule ^$ index.php [L]
# Redirect a request for /something to /#something, assuming it's not a file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ #$1 [NE,R=301,L]
share|improve this answer
Thanks! That's it! – Bert Feb 7 '12 at 12:53

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.