我有一个文件
http://www.www.com/somefile.php
我希望能够访问相同的文件
http://www.www.com/somefile
但我还是需要
http://www.www.com/directory
打开文件
http://www.www.com/directory/index.php
如果,事实上,directory 是一个目录。
这是使用 Red Hat 和 Apache 的典型 LAMP 设置。
这可能吗?如果是,怎么办?
最佳答案
apache 重写规则将为您完成此操作。唯一的限制是你不能有一个名为“somefile.php”的文件和一个名为“somefile”的目录(尽管你仍然可以有目录。
这是一个支持多个文件名的示例规则(只需放入您的 .htaccess 文件中)。
RewriteEngine on
RewriteRule ^(somefile1|somefile2|somefile3) $1.php
会将/somefile1 更改为/somefile1.php,将/somefile2 更改为/somefile2.php,将/somefile3 更改为/somefile3.php。
关于php - 是否可以在没有扩展名的情况下在 apache 中运行 php 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2204316/