Add Trailing Slash .htaccess

核能气质少年 提交于 2019-11-26 11:16:31

问题


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.

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]

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?


回答1:


RewriteCond %{REQUEST_URI} !(/$|\.) 
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L] 



回答2:


Please add below lines top of .htaccess file

RewriteEngine on
#Add Trailing slash for end of the URL
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R]


来源:https://stackoverflow.com/questions/11829714/add-trailing-slash-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!