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!

link|improve this question
Your example is missing things you are asking for. E.g. RewriteRule ^index.php\/(.*)$ \#$1 – pduersteler Feb 6 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 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 at 14:43
feedback

1 Answer

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]
link|improve this answer
Thanks! That's it! – Bert Feb 7 at 12:53
feedback

Your Answer

 
or
required, but never shown

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