添加尾随斜线网址 [英] Add Trailing Slash to URLs
本文介绍了添加尾随斜线网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有相当多的结果加斜杠的.htaccess 谷歌,但我发现所有的例子都需要使用你的域名,如下面的例子:
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 ^(.*)$ http://domain.com/$1/ [L,R=301]
我的问题是一个硬codeD域名将不能在我的本地开发工作。有没有一种方法来添加结尾的斜杠没有明确告诉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.
这篇关于添加尾随斜线网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文