views:

312

answers:

1

i'm weak in regular expressions, i need to redirect any FileName.htm or FileName.html page request to ./#FileName, only if the request is incoming from an outside link. These files will all reside in the root directory.

this is what i have so far. it gives me errors : (

RewriteCond %{REQUEST_FILENAME} !index.html$|!index.htm$ [NC]
RewriteCond %{HTTP_REFERER} !^$ 
RewriteCond %{HTTP_REFERER} !example\.com [NC]  
RewriteRule ^([a-zA-Z0-9\-_]+)\.html$ /#$1 [NE, R]

the first line makes sure only index files are not redirected. the second line doesn't redirect if the request is coming from an unknown referrer the third line excludes my domain from the redirection rule the fourth line redirects it to the hash link.

which doesn't seem to work.
and please if there is a more efficient way to write this, i would be grateful. thank you!

A: 

Try this rule:

RewriteCond $1 !=index [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https?://(www\.)?example\.com/ [NC]
RewriteRule ^([a-zA-Z0-9\-_]+)\.html?$ /#$1 [NE,R]
Gumbo
Hi!i added your code to my .htaccess file and made a test page for it here http://dl.dropbox.com/u/428209/test-link.htmland even tho the error is gone, it doesn't seem to redirect. thank you : )
Mohammad
@Mohammad: Hm, it works for me.
Gumbo
you're right! i was using "open in new tab" ah that's why.. and may i know what the ß does in "wwwß"? i googled for it without any success. thank youuUU!!!
Mohammad
@Mohammad: Just a typo. On german keyboards the \ character resides on the same key as the ß character but needs the modifying key *AltGr* to be pressed. I just missed to press that key.
Gumbo
ok ok thank you! you're amazing.
Mohammad