向 URL 添加尾部斜杠

编程入门 行业动态 更新时间:2024-10-26 14:29:22
本文介绍了向 URL 添加尾部斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

add trailing 的结果相当多斜线 .htaccess 在 Google 上,但我发现的所有示例都需要使用您的域名,如下例所示:

There are quite a few results for add trailing slash .htaccess on Google, but all examples I found require the use of your domain name, as in this example:

RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !example.php RewriteCond %{REQUEST_URI} !(.*)/$ RewriteRule ^(.*)$ domain/$1/ [L,R=301]

我的问题是硬编码的域名在我的本地开发机器上不起作用.有没有办法在不明确告诉 mod_rewrite 域名的情况下添加尾部斜杠?

My problem is that a hard-coded domain name will not work on my local development machine. Is there a way to add trailing slashes without explicitly telling mod_rewrite the domain name?

推荐答案

不需要指定域,直接使用绝对URL路径即可:

You don’t need to specify the domain, you can simply use an absolute URL path:

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

这也会检查 URL 方案是否已过时.

That does also make a check for the URL scheme obsolete.

更多推荐

向 URL 添加尾部斜杠

本文发布于:2023-11-01 11:23:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549210.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:斜杠   尾部   URL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!