开发者

How do I remove a trailing slash?

I just want to remove a trailing slash from a directory. For example I want /p/page/ to show up as /p/page. It just looks better, doesn't it?

However I've tried many different kinds of mod_rewrites but none have worked or something happened.

I just want this to apply to subfolders (even bette开发者_开发知识库r, any slash in a folder in a folder in a folder like /a/b/c), not /p/ as this may affect other parts of my site in a negative way.


You can try adding the following line to your .htaccess file:

DirectorySlash Off

That solved the problem for me a while ago. Of course if the path is only / I don't think you can get rid of it.


Copy this code in your root .htaccess file (directly under DOCUMENT_ROOT):

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{REQUEST_URI} !/$
RewriteRule ^ %{REQUEST_URI}/ [L]

DirectorySlash Off
RewriteCond %{THE_REQUEST} ^GET\s(.*)/\s
RewriteRule ^ %1 [R=302,NE,L]

It will externally redirect http://localhost/blog/ to http://localhost/blog while still displaying default index.html or index.php or whatever under /blog directory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜