htaccess 将 .php 添加到没有扩展名的所有内容中 [英] htaccess add .php to everything without an extension already

查看:24
本文介绍了htaccess 将 .php 添加到没有扩展名的所有内容中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在四处寻找重复项,但我无法找到我认为应该是一个简单答案的答案.

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 添加到没有扩展名的所有内容中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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