Trailing slash and initial www

六眼飞鱼酱① 提交于 2019-12-13 14:21:59

问题


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!


回答1:


I think you need to add something like this before your last rewrite rule, to avoid rewriting URIs that already end in .php

RewriteCond %{REQUEST_URI} !\.php$


来源:https://stackoverflow.com/questions/2261455/trailing-slash-and-initial-www

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!