.htaccess搞乱了.php扩展名? [英] .htaccess Messing up with .php extension?

查看:63
本文介绍了.htaccess搞乱了.php扩展名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,所以我有这个mod_rewrite规则,如果发送请求时未提供,则在内部附加.html扩展名:

Ok, so I have this mod_rewrite rule that internally attaches a .html extension if it is not provided when sending the request:


Options +FollowSymLinks
RewriteEngine on
#
## Internally rewrite extensionless file requests to .html files ##
#
# If the requested URI does not contain a period in the final path-part
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
# and if it does not exist as a directory
RewriteCond %{REQUEST_FILENAME} !-d
# and if it does not exist as a file
RewriteCond %{REQUEST_FILENAME} !-f
# then add .html to get the actual filename
RewriteRule (.*) /$1.html [L]
#
#
## Externally redirect clients directly requesting .html page URIs to extensionless URIs
#
# If client request header contains html file extension
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+html\ HTTP 
# externally redirect to extensionless URI
RewriteRule ^(.+)\.html$ http://www.example.com/$1 [R=301,L]

我考虑过将显示为.html的任何地方更改为.php该文件的第一部分,以便当有人请求.php文件而不添加扩展名时,它仍将转到该.php页面。原来,这行不通。为什么不呢?

I thought about changing anywhere it says .html to .php in the first part of this file so that when someone requests a .php file without adding it's extension, it would still go to that .php page. Turns out, this doesn't work. Why not?

我在这里的证据: http:// appstorecrazy .com / OHNOEZ / NOTEST

推荐答案

尝试以下处理php的规则:

Try following rules for handling php:

## Internally rewrite extensionless file requests to .php files ##
# If the requested URI does not contain a period in the final path-part
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
# and if it does not exist as a directory
RewriteCond %{REQUEST_FILENAME} !-d
# and if it does not exist as a file
RewriteCond %{REQUEST_FILENAME} !-f
# then add .html to get the actual filename
RewriteRule (.*) /$1.php [L]

## Externally redirect clients directly requesting .php page URIs to extensionless URIs
#
# If client request header contains html file extension
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+)\.php
# externally redirect to extensionless URI
RewriteRule ^(.+)\.php$ /$1 [R=301,L]

这篇关于.htaccess搞乱了.php扩展名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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