尾随斜线和初始WWW [英] Trailing slash and initial www

查看:134
本文介绍了尾随斜线和初始WWW的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的htaccess的:

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]

所以,我的PHP文件可以被称为不带.php扩展。

So my .php files can be called without the .php extension.

不过,我希望他们可以只用斜线调用。所以,当这最后的斜线没有给出,就应该用301这个问题我已经附加的是,这是给我的问题与最初的WWW,和PHP扩展本身(有时是加入递归的.php)。

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).

如何能不能做到?

谢谢!

推荐答案

我想你需要添加这样的事情你最后重写规则之前,为避免重复已经以.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

RewriteCond %{REQUEST_URI} !\.php$

这篇关于尾随斜线和初始WWW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆