我在.htaccess文件中使用伪指令来清理我的网站URL。
I use directives in an .htaccess file to clean-up my website URLs.
例如,此伪指令添加了斜杠:
For instance, this directive adds a trailing slash:
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$ RewriteRule (.*)$ /$1/ [R=301,L]并删除文件扩展名:
# hide .php file extensions RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC] RewriteRule ^ %1 [R=301,L] # redirect .html to / RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC] RewriteRule ^ %1 [R,L] # redirect .htm to / RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.htm [NC] RewriteRule ^ %1 [R,L]我遇到的问题是页内锚。当我创建指向页面一部分的链接时,像这样:
The problem I'm having is with in-page anchors. When I create a link to a section of page, like this:
www.mywebsite/privacy-policy#information-we-collect系统输出以下内容:
www.mywebsite/privacy-policy/#information-we-collect当涉及页面内锚链接时,如何调整.htaccess文件以使尾部斜杠要求例外?
How do I adjust the .htaccess file to make an exception for the trailing slash requirement when it comes to in-page anchor links?
一个相关的问题是:
尽管这两个链接都起作用:
Although both of these links work:
www.mywebsite/privacy-policy#information-we-collect www.mywebsite/privacy-policy/#information-we-collect... 在页面内部(在本例中为隐私权政策。)。
... when they are inside the page (Privacy Policy, in this case).
URL永远不会在地址栏中进行调整以显示片段标识符(#... )。地址栏固定为:
The URL never adjusts in the address bar to show the fragment identifier (#...). The address bar stays fixed at:
www.mywebsite/privacy-policy/通常它会调整为:
www.mywebsite/privacy-policy#information-we-collect最后,虽然这些带有片段标识符的链接在其页面中有效,但是带有片段标识符到另一个页面的链接却不起作用。
Lastly, while these links with fragment identifiers work within their page, a link with a fragment identifier to another page, does not work.
所以,如果我m在隐私权政策页面上,所有这些链接都可以正常工作:
So, if I'm on the Privacy Policy page, all these links work fine:
www.mywebsite/privacy-policy#information-we-collect www.mywebsite/privacy-policy/#information-we-collect www.mywebsite/terms-of-service/但这完全没有响应:
www.mywebsite/terms-of-service#limitation-of-liability仅在服务条款页面中有效。
It only works within the Terms of Service page.
解决方案将我的评论转换为答案。
Converting my comments to an answer.
此异常无效:
更多推荐
页内锚链接的htaccess异常
发布评论