Php 影响HTACCESS重定向的URL尾部斜杠

Php 影响HTACCESS重定向的URL尾部斜杠,php,.htaccess,redirect,Php,.htaccess,Redirect,我已使用以下Htaccess代码成功地将我的站点URL从“localhost/example/user.php?u=user1”重定向到“localhost/example/user1”: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/\.]+)/?$ user.php?u=$1 但现在,当我打开带有尾随斜杠的站点时,它会将我重定向到localhost/user1

我已使用以下Htaccess代码成功地将我的站点URL从“localhost/example/user.php?u=user1”重定向到“localhost/example/user1”

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ user.php?u=$1
但现在,当我打开带有尾随斜杠的站点时,它会将我重定向到localhost/user1,我尝试了许多方法从url中删除尾随斜杠,但它不起作用

如何做到这一点


谢谢。

将RewriteBase设置为您的工作目录

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

将RewriteBase设置为工作目录

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

你还有其他修改规则吗?@JonLin,没有,先生,这是我的.htaccess文件的完整编码,
#11--建立一个自定义404页面。ErrorDocument 404/filenotfound.php#2 2------在RewriteCond%{REQUEST_FILENAME}上阻止目录文件IndexIgnore*重写引擎-f RewriteCond%{REQUEST_FILENAME}-重写规则^([^/\.]+)/?$user.php?u=$1
你还有其他的mod重写规则吗?@JonLin,没有,先生,这是我的.htaccess文件的完整编码,
\1---建立一个自定义404页面。ErrorDocument 404/filenotfound.php#2 2------在RewriteCond%{REQUEST_FILENAME}上阻止目录文件IndexIgnore*重写引擎-f RewriteCond%{REQUEST_FILENAME}-重写规则^([^/\.]+)/?$user.php?u=$1
RewriteBase不起作用,它给出了以下错误:未找到请求的URL/var/www/web\u intersect/user.php在此服务器上未找到。尝试了很多次后,我将RewriteBase设置为RewriteBase/web\u intersect/当我试图在localhost/example/user1/末尾用斜线打开网站时,它没有CSS样式。抱歉是我的错。我编辑了上面的代码。如何包含CSS样式?您应该提供绝对路径。因此,如果像
那样包含它们,则必须像
那样提供绝对路径。或者,您可以像这样设置基本url
。我包括了类似
的样式表,我将它们更新为
,并且成功了。Thank.RewriteBase无法正常工作,出现以下错误:未找到此服务器上未找到请求的URL/var/www/web\u intersect/user.php。经过多次尝试,我已将RewriteBase设置为RewriteBase/web\u intersect/并且当我尝试在localhost/example/user1/末尾用斜线打开网站时,它已打开,但没有CSS样式。对不起,我的错误。我编辑了上面的代码。如何包含CSS样式?您应该提供绝对路径。因此,如果像
那样包含它们,则必须像
那样提供绝对路径。或者,您可以像这样设置基本url
。我包括了类似
的样式表,我将它们更新为
,并且成功了。谢谢