【发布时间】:2018-07-28 23:08:03
【问题描述】:
我想使用与 php 文件位于同一文件夹中的 .htaccess 文件从 URL 中删除 .php 扩展名(我想删除所有文件的扩展名,而不仅仅是其中一个文件)。我使用以下代码:
Options +FollowSymLinks # I found this on the Internet trying to solve this problem, but nothing changed
RewriteEngine On
RewriteBase /app_tests/ # This is the folder where I want to delete the .php extension, it's located in the htdocs folder
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L] #I have tried without QSA as well (I don't really know what it does)
理论上,当我访问 myweb.com/index 时,我应该会看到 index.php 页面,但在输入该地址时会出现 403 错误(禁止访问)。当然,没有叫 index 的目录。我知道代码可以工作(或至少做某事),因为当我写错时,它会说内部服务器错误,因为如果我删除或评论它(#),我得到的错误是 404(未找到)。
我正在使用适用于 Windows 的最新版本的 XAMPP 之一。我已取消注释 httpd.conf 文件中的以下行以加载模块:
LoadModule rewrite_module modules/mod_rewrite.so
有谁知道我做错了什么或如何解决这个问题?谢谢!
【问题讨论】:
标签: apache .htaccess mod-rewrite xampp httpd.conf