添加“/”时遇到问题到 URI 结尾

发布于 2024-10-24 19:45:35 字数 411 浏览 0 评论 0原文

现在我有一个类似于

http://www.example.com/customer/login

我希望 URI 始终有一个结束路径,因为我会使用带有 ../ 的重定向 如果它没有斜杠,它就会把一切搞乱,如果它有斜杠,它就可以正常工作。我尝试在网上查看一些示例,但我无法真正得到任何东西,这是我当前的 .htaccess 文件

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?rt=$1 [QSA] 

Right now i have a url which is like

http://www.example.com/customer/login

i want the URI to always have a ending trail because ill use redirects with ../
and if it doesnt have slash it messes everything up if it has a slash it works fine. I tried to look at some examples online but i couldnt really get anything to work heres my current .htaccess file

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?rt=$1 [QSA] 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

与酒说心事 2024-10-31 19:45:36

阿努巴瓦得到了基本的答案,我对他进行了修改。您需要发送 HTTP 重定向以使浏览器请求以 / 结尾的 URL。

要与现有的重写规则合并,您应该执行以下操作:

RewriteEngine on

# First check it's not a file
RewriteCond %{REQUEST_FILENAME} !-f
# And it doesn't end in /
RewriteCond %{REQUEST_URI} !.*/$
# Send the redirect. I would do 301 (permanent) here
# the "L" means the rest of the rules are ignored for this request
RewriteRule ^(.*)$ $1/ [L,R=301]

# Now pass thru to your old ruleset URLs the slash-checker didn't catch
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?rt=$1 [QSA]

Anubhava's got the basic answer and I modded him up. You need to send an HTTP redirect to get the browser to request the URL with the / at the end.

To merge with your existing rewrite rules, you should do:

RewriteEngine on

# First check it's not a file
RewriteCond %{REQUEST_FILENAME} !-f
# And it doesn't end in /
RewriteCond %{REQUEST_URI} !.*/$
# Send the redirect. I would do 301 (permanent) here
# the "L" means the rest of the rules are ignored for this request
RewriteRule ^(.*)$ $1/ [L,R=301]

# Now pass thru to your old ruleset URLs the slash-checker didn't catch
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?rt=$1 [QSA]
上课铃就是安魂曲 2024-10-31 19:45:36

这个怎么样:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L,R=302]

How about this:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [L,R=302]
原谅过去的我 2024-10-31 19:45:36

尝试使用以下规则

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?rt=$1 [QSA] 

#following rule checks if url is not ending with / and
#if not then redirected to url which is ending with /
RewriteCond %{REQUEST_URI} !.*/$
RewriteRule ^(.*)$  $1/ [R=302,L]

Try using following rules

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?rt=$1 [QSA] 

#following rule checks if url is not ending with / and
#if not then redirected to url which is ending with /
RewriteCond %{REQUEST_URI} !.*/$
RewriteRule ^(.*)$  $1/ [R=302,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文