添加尾随斜线的.htaccess [英] Add Trailing Slash .htaccess

查看:282
本文介绍了添加尾随斜线的.htaccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图得到以下效果(使用本本地文件的http://本地主机/ [COMPANY_NAME] / [PROJECT_NAME] /.htaccess ):

 的http://本地主机/ [COMPANY_NAME] / [PROJECT_NAME] /页1(加斜杠)
HTTP://本地主机/ [COMPANY_NAME] / [PROJECT_NAME] /页1 /(什么都不做)
HTTP://本地主机/ [COMPANY_NAME] / [PROJECT_NAME] /页,1 /子页面-1(加斜杠)
http://www.example.com/page-1(加斜杠)LT; BR />
http://www.example.com/page-1/(什么都不做)
等等
 

我要完成的事情是,这个的.htaccess不需要路径的http://本地主机/ [COMPANY_NAME] / [PROJECT_NAME] / 再使我没有编辑这个它已经每次上传。

 的RewriteCond%{} REQUEST_FILENAME!-f
重写规则^(。* [^ /])/ $ 1 / [L,R = 301]
 

我发现code以上的位置:添加尾随斜线网址的,但它仅使得可以动态地使用HOST和丢弃的路径。是否有人的解决方案来实现这种效果呢?

解决方案

 的RewriteCond%{REQUEST_URI}!(/ $ | \)
重写规则(。*)%{REQUEST_URI} / [R = 301,L]
 

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?

解决方案

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

这篇关于添加尾随斜线的.htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆