htaccess的.PHP添加到一切不带扩展名已 [英] htaccess add .php to everything without an extension already
问题描述
我环顾四周SO的重复,但我无法找到我认为应该是一个简单的答案。
I'm looking around SO for duplicates, but I'm having trouble finding what I think should be a simple answer.
什么是重写规则添加的.php
来任何不带扩展名了?
What are the rewrite rules to add .php
to anything without an extension already?
例子:
www.website.com/styles.css - > www.website.com/styles.css
www.website.com/styles.css -> www.website.com/styles.css
www.website.com/login - > www.website.com/login.php
www.website.com/login -> www.website.com/login.php
谢谢!
推荐答案
以下可满足您的需要:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+)$ $1.php [L]
这将自动添加PHP扩展到文件名不带扩展名。它可能试图重命名something.css到something.css.php,但只有这样做,如果something.css.php存在。
This will automatically add the .php extension to filenames without extensions. It may attempt to rename something.css to something.css.php, but will only do so if something.css.php exists.
这篇关于htaccess的.PHP添加到一切不带扩展名已的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!