Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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]
</IfModule>

Thanks!

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: httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule. You are missing some things. –  pduersteler Feb 6 '12 at 14:43

1 Answer 1

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

 
discard

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.