How to make this .htaccess rule work fine without manual adding there path `/some-dir/` or `RewriteBase /some-dir`?

僤鯓⒐⒋嵵緔 提交于 2019-12-25 04:47:11

问题


I have http://localhost/some-dir/.htaccess RewriteRule ^(.+)/$ /some-dir/$1 [R=301,L] to remove trailing slash from URLs end.

How can I improve the same think with simple .htaccess in http://localhost/some-dir/.htaccess without manual adding there path /some-dir/ or RewriteBase /some-dir? so that this rule works fine if I use it in any server path, like http://localhost/.htaccess or http://localhost/some-dir/else-path/etc/.htaccess etc.


回答1:


You could use REQUEST_URI instead:

RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteRule ^.+/$ %1 [R=301,L]


来源:https://stackoverflow.com/questions/4775142/how-to-make-this-htaccess-rule-work-fine-without-manual-adding-there-path-som

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