使用 Apache 将尾部斜杠添加到 URL
我正在一个名为 testsite 的目录中工作,我希望所有 .php 扩展名都替换为尾部斜杠。我已经完成了一半,(例如)输入 http://mydomain.com/testsite/about 表示 http://mydomain.com/testsite/about.php 已加载。
不过,我现在希望 URL 显示为 ./about/,以便搜索引擎排名中只显示一个版本。
这是我的 .htaccess:
RewriteEngine On
RewriteBase /testsite/
RewriteRule ^()$ index.php [NC,L]
RewriteCond %{REQUEST_URI} !(^/?.*\..*$) [NC]
RewriteRule (.*)$ $1.php [NC]
另外,是否可以保留(并隐藏显示我传递的任何参数)?
非常感谢所有帮助!
I'm working in a directory called testsite and I want all .php extensions to be replaced by a trailing slash. I'm halfway there, in that (for example) entering http://mydomain.com/testsite/about means that http://mydomain.com/testsite/about.php is loaded.
However, I now want the URL to be displayed as ./about/ so that only one version shows up in search engine rankings.
Here's my .htaccess:
RewriteEngine On
RewriteBase /testsite/
RewriteRule ^()$ index.php [NC,L]
RewriteCond %{REQUEST_URI} !(^/?.*\..*$) [NC]
RewriteRule (.*)$ $1.php [NC]
Also, is it possible to preserve (and hide from display any parameters that I pass)?
All help is much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试这些规则:
Try these rules:
尝试将最后一条规则替换为:
Try replacing the last rule with: