简体   繁体   English

URL尾部斜杠影响HTACCESS重定向

[英]URL Trailing Slashes Effecting The HTACCESS Redirection

I have successfully redirect my sites URL from "localhost/example/user.php?u=user1" to "localhost/example/user1" with the following Htaccess code: 我已使用以下Htaccess代码成功将网站URL从“ localhost / example / user.php?u = user1”重定向到“ localhost / example / user1”

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ user.php?u=$1

But now when I open my site with a trailing slash "localhost/example/user1/" it redirects me to localhost/user1 , I have tried many ways to eliminate that trailing slash from url but its not working. 但是现在,当我用斜杠“ localhost / example / user1 /”打开我的站点时,它会将我重定向到localhost / user1 ,我尝试了多种方法来从url中消除该斜杠,但它不起作用。

How it can be done? 怎么做?

THANKS. 谢谢。

Set the RewriteBase to your working dir. 将RewriteBase设置为您的工作目录。

RewriteBase /example/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ user.php?u=$1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM