php - .htaccess 文件不适用于本地主机 XAMPP

标签 php apache .htaccess

我在本地主机上使用 XAMPP 和 .htaccess 文件有 PHP 项目:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /locations/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /test.php [L]
</IfModule>

但这不起作用,我只收到错误 404。在 httpd.conf 文件中,我取消了这一行的注释:

# 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

我使用的是 Windows 8.1。请问我该怎么做才能让它发挥作用?

最佳答案

您可以在 root .htaccess 中使用此规则:

RewriteEngine On
RewriteBase /

RewriteRule ^locations(/.*)?$ test.php [L,NC]

关于php - .htaccess 文件不适用于本地主机 XAMPP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27657810/

相关文章:

apache - 如何对适用于站点上所有路径的 htaccess 重定向设置异常(exception)?

apache - 为多个参数和页面编辑 .htaccess

php - 如何获取文件的DocComment?

php - 具有相同标识符的多个 HTTP GET 参数

php - 如何从 PHP 脚本在 joomla 3.0 中插入和发布新闻

apache - 如何让 map 服务器工作

php - 如何显示两个特定日期之间的数据,日期格式为时间戳

linux - 将 [a-z]* 重定向在 httpd.conf 中工作

apache - 如何使用 sbcl+restas+apache 运行网络应用程序?

.htaccess - 使用 htaccess 将 https 重定向到 http 期望一个 url