问题描述
我正在四处寻找重复项,但我无法找到我认为应该是一个简单答案的答案.
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
谢谢!
推荐答案
以下可能适合您的需求:
The following may suit your needs:
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 添加到没有扩展名的所有内容中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!