重定向非索引页面请求哈希值的.htaccess链接重定向、索引、页面、链接

2023-09-02 09:38:56 作者:还能怎样

我是微弱的常规前pressions,我需要重定向任何 FileName.htm 或 FileName.html 页请求 ./#文件名下,只有当请求从外部链路传入。这些文件都将驻留在根目录下。

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!

推荐答案

试试这个规则:

RewriteCond $1 !=index [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https?://(www.)?example.com/ [NC]
RewriteRule ^([a-zA-Z0-9-_]+).html?$ /#$1 [NE,R]