我在构建自己的CMS和玩.htaccess
文件。
我在网上寻找一段代码,它会在每个HTTP请求上添加一个斜杠。
当我插入代码时,我意识到它也会删除我工作的子目录的名称。
URL:
所以这就是我所拥有的:localhost/project/index.php
这就是我想要的:localhost/projects/index.php/
这是我得到的结果:localhost/index.php/
但真正的问题是:我看到了结果,我想从示例3回到示例1。但在我删除了.htaccess
文件中的代码后,更改仍然存在,我不知道如何恢复。
如何恢复此重写规则?
这是我在实现"尾随斜杠"之前的.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /tesla0.2/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]
</IfModule>
这是我在之后的.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /tesla0.2/
RewriteCond %{REQUEST_URI} !'.(php|html?|jpg|gif)$
RewriteRule ^(.*)([^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]
</IfModule>
我假设您的htaccess文件在"projects"目录中?
尝试将您的规则更改为:
RewriteCond %{REQUEST_URI} !'.(php|html?|jpg|gif)$
RewriteRule ^(.*)([^/])$ http://%{HTTP_HOST}%{REQUEST_URI}/ [L,R=301]
您还需要清除浏览器的缓存,因为重定向是301(永久),浏览器将缓存重定向并无限期使用它,因为它是永久重定向。