【发布时间】:2014-07-11 14:36:47
【问题描述】:
我正在尝试实现 url 重写以从 php 文件中删除 php 扩展名,但我不知道出了什么问题! 我在 ubuntu 机器上使用 Lampp,我什至在 httpd.conf 中将 AllowOverride 从 none 设置为 All:
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All <--- I set it from "None" to "All"
并且我已将我的 .htacces 文件放在我的项目文件夹的根目录中,即。项目/测试/(我什至不知道这是 .htaccess 文件的正确位置)。我的本地主机 url 就像:http://localhost/projects/test/abc.php。我希望将其设置为http://localhost/projects/test/abc。这是我的 url 重写代码:
Options +FollowSymLinks -MultiViews
<IfModule mod_rewrite.so>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
</IfModule>
我什至尝试过<IfModule mod_rewrite.c>
【问题讨论】:
-
I cannot figure out what's wrong!你能想到什么?当你使用你的规则时会发生什么?你的 error_log 和 rewrite_log 向你展示了什么?是否在服务器 httpd.conf 上的 loadmodules 中启用了 mod_rewrite? -
抱歉我的无知,我是 .htaccess 的新手。正如我所说,我想从 abc.php 中删除 .php 扩展名。问题是浏览器仍然将 url 显示为localhost/projects/test/abc.php(应该是localhost/projects/test/abc)。再次抱歉,我不知道在哪里可以找到您提到的那些日志文件。
-
使用当前规则,您将添加
.php扩展而不是删除它。 -
请先使用搜索引擎,因为这是一个使用 mod_rewrite 的简单任务,之前已经解决了几千次。
-
@feeela 我正在关注这里提到的教程:alexcican.com/post/…,并且我已经将代码与不同的 stackoverflow 答案相结合。你能写出删除 .php 扩展名的代码吗?
标签: php .htaccess mod-rewrite ubuntu lampp