22

我正在使用 XAMPP,但我无法在本地主机上使用 .htaccess 文件。我尝试了很多次.. 在线工作良好。但本地主机显示[在此服务器上找不到请求的 URL]

我的根文件夹是真实的

localhost/acre/real/property_available.php
localhost/acre/real/properties


<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /acre/real/
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^properties$ /property_available.php/$1 [NC,QSA]
</IfModule>

4

9 回答 9

50

Just had a similar issue

Resolved it by checking in 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   <--- make sure this is not set to "None"

It is worth bearing in mind I tried (from Mark's answer) the "put garbage in the .htaccess" which did give a server error - but even though it was being read, it wasn't being acted on due to no overrides allowed.

于 2013-11-24T21:33:37.500 回答
32

在 conf/extra/httpd-vhosts.conf 中,AllowOverride All为您遇到问题的所有网站添加该行

<VirtualHost example.site:80>
    # rest of the stuff
    <Directory "c:\Projects\example.site">
        Require all granted
         AllowOverride All <-----This line is required
    </Directory>
</VirtualHost>
于 2015-03-07T07:26:51.807 回答
13

尝试

<IfModule mod_rewrite.so>
...
...
...
</IfModule>

代替<IfModule mod_rewrite.c>

于 2013-12-18T09:58:08.597 回答
6

在没有看到您的系统的情况下,很难判断出了什么问题,但请尝试以下操作(如果这些对日志错误消息不起作用,请评论答案)

[停止您的 Apache 服务器实例。确保它没有运行!]

1) 将 apache server/install 移动到没有长文件名和空格的文件夹

2) 检查 install\conf 文件夹中的 httpd.conf 并查找AccessFileName. 如果是.htaccess将其更改为 windows 接受的文件名(例如conf.htaccess

3)仔细检查您的 htaccess 文件是否被读取:向其中添加一些无法解释的垃圾并启动服务器:您应该收到错误 500. 如果你不这样做,文件没有被读取,重新访问 httpd.conf 文件(如果看起来没问题,检查这是否是唯一定义 htaccess 的文件及其位置,它只在一个地方 - 在文件内 - ; 还检查 httpd.conf 和 htaccess 文件是否都可以访问:未加密,文件访问权限不受限制,驱动器/路径可用 - 并且没有长文件夹路径和文件名 -)
再次停止 Apache,然后继续:
4) 如果你的系统上也有 IIS,从services.msc

中停止它(如果可以的话也卸载它) 5)将以下内容添加到有效 htaccess 文件的顶部:
RewriteEngine On
RewriteLog "/path/logs/rewrite.log" #确保路径在那里!
RewriteLogLevel 9

6) 清空您的 [apache]\logs 文件夹(如果您使用另一个文件夹,则使用那个 :)

7)检查以下条目是否已设置并正确:
Action application/x-httpd-php "c:/your-php5-path /php-cgi.exe"
LoadModule php5_module "c:/your-php5-path/php5apache2.dll"
LoadModule rewrite_module modules/mod_rewrite.so
在安装 phpX 时避免使用长路径名和文件夹名中的空格!

8) 启动 apache 服务器

您可以执行上述所有步骤或逐个进行,您的呼叫。但在一天结束时,请确保您尝试了以上所有内容!
如果系统仍然崩溃并且您无法修复它,请从日志文件夹复制并粘贴错误消息以获得进一步帮助

于 2013-06-18T08:50:53.797 回答
4

我有一个类似的问题。但问题出在文件名“.htaccess”中,因为 Windows 不允许文件名以“.”开头,解决方案是使用 CMD 命令重命名文件。“重命名 c:\xampp\htdocs\htaccess.txt .htaccess”

于 2016-03-04T14:43:28.270 回答
1

对于 MacOS 上的 xampp vm,high sierra,MacOS Mojave (10.12+),你可以按照这些

1. mount /opt/lampp
2. explore the folder
3. open terminal from the folder
4. cd to `htdocs`>yourapp (ex: techaz.co)
5. vim .htaccess
6. paste your .htaccess content (that is suggested on options-permalink.php)

在此处输入图像描述

于 2019-05-14T14:14:58.467 回答
0

我也为我的本地主机设置了 xampp,在设置期间或之后我没有对 xampp 创建的文件做任何事情。

但在“.htaccess”文件中,请确保您已将其设置为类似的内容。对我有用,这对你没有任何影响。

RewriteEngine On
RewriteRule ^filename/?$ filename.html

将 .html 更改为您使用的任何格式。

确保您的安装是干净的,并且只需制作 .htaccess 文件。还要记住为每个目录放置一个 .htaccess 文件(真的不知道是否可以为所有文件夹使用一个文件,但为了安全起见,只要这样做,它就会一直有效。

于 2019-04-13T00:08:12.090 回答
0

对于 Windows 用户,请务必仔细查看此部分。

RewriteRule ^properties$ /property_available.php/$1 [NC,QSA]

正如Apache 文档中所说:

mod_rewrite 模块使用基于规则的重写引擎,基于 PCRE 正则表达式解析器,动态重写请求的 URL。

所以意味着Apache^properties$只会寻找. properties您可能想尝试此代码。

RewriteRule properties /property_available.php/$1 [NC,QSA]

因此 Apache 将看到具有的 URLproperties并将其重写为/property_available.php/

于 2018-10-14T08:55:08.527 回答
-1

编辑 .htaccess 文件,使第一行显示为“Test.”:

测试。

设置默认处理程序

DirectoryIndex index.php index.html index.htm

...

于 2020-07-16T00:23:02.147 回答