我已经成功修改了我的 .htaccess 文件以删除大多数页面上的尾部斜杠,但我想知道如何免除我的主页/目录?例如:
I've successfully modified my .htaccess file to remove trailing slashes on most pages but I'm wondering how to exempt my home page/directory? For example:
domain/test/成功重定向到 domain/test
domain/test/ successfully redirects to domain/test
但是,当我访问我的域时,它会附加根文档
HOWEVER, when I hit my domain it will append the root document
domain/重定向到 domain/index.php
domain/ redirects to domain/index.php
是否有条件可以添加以忽略根 url 尾部斜杠,以便它不会尝试删除尾部斜杠并添加我的默认脚本?这是我到目前为止所拥有的:
Is there a condition that I can add to ignore root url trailing slash so that it doesn't attempt to remove the trailing slash and add my default script? Here's what I have so far:
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} ^(.+)/$ RewriteRule ^(.+)/$ /$1 [R=301,L] 推荐答案好的.经过一系列的反复试验,我回答了我自己的问题.
OK. After a bunch of trial and error I answered my own question.
第三行表示 URI 中必须有内容才能执行重定向,因此如果 url 仅包含初始斜杠,则不会重定向.
The third line denotes that there has to be something in the URI in order to perform the redirect thus not redirecting if the url just contains the initial slash.
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} (.*)$ RewriteRule ^(.+)/$ www.domain/$1 [R=301,L]更多推荐
使用 .htaccess 删除尾部斜杠,主页/登陆页面除外
发布评论