开发者

redirect non-index page requests to hash links with .htaccess

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开发者_如何学Python_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!


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]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜