尾部斜杠和首字母 www
我有这个 htaccess:
RewriteEngine On
# redirect with www
RewriteCond %{HTTP_HOST} ^mydomain [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1/ [R=301,L]
# add .php internally
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]
所以我的 .php 文件可以在没有 .php 扩展名的情况下调用。
但我希望仅用尾部斜杠来调用它们。因此,当未给出尾部斜杠时,应附加 301。我遇到的问题是,这给我带来了初始 www 和 .php 扩展本身的问题(有时它会递归地添加 .php)。
怎么办呢?
谢谢!
I have this htaccess:
RewriteEngine On
# redirect with www
RewriteCond %{HTTP_HOST} ^mydomain [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1/ [R=301,L]
# add .php internally
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]
So my .php files can be called without the .php extension.
But I'd like them to be called only with a trailing slash. So when this trailing slash is not given, it should be appended with a 301. The problem I have is that this is giving me problems with the initial www, and the .php extension itself (sometimes it is adding recursively .php).
How can it be done?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你需要在最后一个重写规则之前添加类似的内容,以避免重写已经以 .php 结尾的 URI
I think you need to add something like this before your last rewrite rule, to avoid rewriting URIs that already end in .php