【问题标题】:.htaccess file not working on localhost XAMPP.htaccess 文件在 localhost XAMPP 上不起作用
【发布时间】:2015-02-23 19:20:39
【问题描述】:

我在 localhost 上使用 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。请问我该怎么做才能让它工作?

【问题讨论】:

  • C:\xampp\htdocs\myProjectRoot
  • 因为我想重定向 url - 当我请求 localhost/myProjectRoot/locations/ 时,我想重定向到 localhost/myProjectRoot/test.php。我猜它在生产服务器版本上运行良好,但由于这个 .htaccess 问题而不在 localhost 上运行。
  • 但是我没有位置文件夹,我想要这个:当用户键入 localhost/myProjectRoot/locations/ 时,它会将他“重定向”到 localhost/myProjectRoot/test.php。所以它会请求这个 php 文件。但我也尝试创建文件夹位置并将此 .htaccess 放在那里,但它不起作用。

标签: php apache .htaccess


【解决方案1】:

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

RewriteEngine On
RewriteBase /

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

【讨论】:

  • 我通过从 Apache 配置文件中删除 Require all denied 启用了 .htaccess。它可以工作,我收到错误 500。但是这个 .htaccess 仍然无法正常工作,因为我需要(重定向)。
  • 另外,我应该添加什么,如果我需要将“localhost/myProjectRoot/locations/”之后的每个字符串的所有 url 重定向到 test.php。例如 localhost/myProjectRoot/locations/123456 将转到 localhost/myProjectRoot/test.php
  • 另外,我应该添加什么,如果我需要将“localhost/myProjectRoot/locations/”之后的每个字符串的所有 url 重定向到 test.php。例如 localhost/myProjectRoot/locations/123456 将转到 localhost/myProjectRoot/test.php
【解决方案2】:

使用 XAMPP,您将在以下位置找到该文件:

{xampp_dir}/apache/conf/httpd.conf

搜索以下字符串:

LoadModule rewrite_module modules/mod_rewrite.so

并取消注释(删除“#”号)。 现在搜索另一个字符串 AllowOverride None 并将其替换为 AllowOverride All

【讨论】:

  • 我做到了,但不幸的是重新启动 Apache 后,没有任何改变。
猜你喜欢
  • 2015-07-04
  • 2016-03-14
  • 2015-07-01
  • 2017-07-27
  • 2021-06-11
  • 1970-01-01
  • 2016-07-17
  • 2013-10-12
  • 2017-08-07
相关资源
最近更新 更多