htaccess的删除HTML和PHP复制不工作 [英] htaccess remove html and php duplicated is not working

查看:130
本文介绍了htaccess的删除HTML和PHP复制不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个片段中工作正常去除PHP扩展

this snippet works fine for removing php extension

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

不过,如果我添加HTML的条件,将无法正常工作

However, if I add html condition, it will not work

RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html

难道我做错了什么?

Did I do something wrong?

推荐答案

您可以在根目录下尝试此相反,在一个.htaccess文件:

You may try this instead, in one .htaccess file at root directory:

Options +FollowSymlinks -MultiViews
RewriteEngine On

RewriteCond %{REQUEST_FILENAME}      !-d
RewriteCond %{REQUEST_FILENAME}.php   -f
RewriteCond %{REQUEST_URI}   !\.php   [NC]
RewriteRule .*   %{REQUEST_URI}.php   [NC,L]

RewriteCond %{REQUEST_FILENAME}      !-d
RewriteCond %{REQUEST_FILENAME}.html  -f
RewriteCond %{REQUEST_URI}   !\.html  [NC]
RewriteRule .*   %{REQUEST_URI}.html  [NC,L]

您应该知道在你的code ++工程的实施只有当请求没有斜杠。我只是修改了code的工作,但我认为这是值得没有什么问题。例如:

You should be aware the implementation in your code works only when the request doesn't have a trailing slash. I just modified your code to work, but I think it's worth nothing that problem. For example:

对于像 http://example.com/filename/ 的要求,该文件以配合状态的RewriteCond%{} REQUEST_FILENAME的.php -f 文件名/ .PHP 。该文件可以不存在,因此,各个规则将被从未使用过。

For a request like http://example.com/filename/, the file to match with condition RewriteCond %{REQUEST_FILENAME}.php -f is filename/.php. That file can't exist, therefore, the respective rule will be never used.

在previous code添加这些行后, RewriteEngine叙述在

Add these lines after RewriteEngine On in the previous code:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI}  /(.*[^/]+)/$ [NC]
RewriteRule .*              /%1          [NC,L]

这篇关于htaccess的删除HTML和PHP复制不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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