本文介绍了向 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 添加尾部斜杠
发布评论