添加尾部斜杠 .htaccess [英] Add Trailing Slash .htaccess
问题描述
我正在尝试获得以下效果(使用此本地文件 http://localhost/[company_name]/[project_name]/.htaccess
):
I'm trying to get the following effect (using this local file http://localhost/[company_name]/[project_name]/.htaccess
):
http://localhost/[company_name]/[project_name]/page-1 (adds slash)
http://localhost/[company_name]/[project_name]/page-1/ (does nothing)
http://localhost/[company_name]/[project_name]/page-1/subpage-1 (adds slash)
http://www.example.com/page-1 (adds slash)<br />
http://www.example.com/page-1/ (does nothing)
etc.
我想要完成的事情是这个 .htaccess 不再需要路径 http://localhost/[company_name]/[project_name]/
这样我就不必每次上传时对其进行编辑.
The thing I want to accomplish is that this .htaccess doesn't need the path http://localhost/[company_name]/[project_name]/
anymore so that I don't have to edit this each time it's been uploaded.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R=301]
我在这里找到了上面的代码:向 URL 添加尾随斜杠,但它只能动态使用 HOST 并丢弃路径.有人有解决方案来实现这种效果吗?
I found the code above here: Add Trailing Slash to URLs, but it only makes it possible to use the HOST dynamically and discards the path. Does someone a solution to accomplish this effect?
推荐答案
RewriteCond %{REQUEST_URI} !(/$|.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
这个代码需要放在你的.htaccess文件的顶部,下面是RewriteEngine On
This code needs to be put at the top of your .htaccess file below RewriteEngine On
这篇关于添加尾部斜杠 .htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!