我正在尝试获得以下效果(使用此本地文件 localhost/[company_name]/[project_name]/.htaccess):
I'm trying to get the following effect (using this local file localhost/[company_name]/[project_name]/.htaccess):
localhost/[company_name]/[project_name]/page-1 (adds slash) localhost/[company_name]/[project_name]/page-1/ (does nothing) localhost/[company_name]/[project_name]/page-1/subpage-1 (adds slash) www.example/page-1 (adds slash)<br /> www.example/page-1/ (does nothing) etc.我想要完成的事情是这个 .htaccess 不再需要路径 localhost/[company_name]/[project_name]/ 这样我就不必每次上传时对其进行编辑.
The thing I want to accomplish is that this .htaccess doesn't need the path 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
发布评论