XAMPP .htaccess mod_rewrite 不工作
我正在为 Windows 5.6.11 运行 XAMPP.我有以下 PHP 文件:
I am running XAMPP for Windows 5.6.11. I have the following PHP file:
C:xampphtdocswww.johndoe.comindex.php
我正在访问的
http://localhost/www.johndoe.com/
事实上,我需要访问以下页面:
As a matter of fact I need to access the following page:
http://localhost/www.johndoe.com/?value=about
作为以下两种之一:
http://localhost/www.johndoe.com/about/
http://localhost/www.johndoe.com/about
所以我的 .htaccess 文件中有以下内容:
so I have the following in my .htaccess file:
RewriteEngine on
RewriteRule ^www.johndoe.com/about/?$ www.johndoe.com/?value=about
但是,这不起作用,因为访问以前的网站会给我一个 401(未找到).
However, this is not working, as accessing the former sites gives me a 401 (not found).
这是我在 C:xamppapacheconfhttpd.conf
中的内容:
Here is what I have in C:xamppapacheconfhttpd.conf
:
<Directory />
AllowOverride none
Require all denied
</Directory>
DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
我必须怎么做才能解析我的 .htaccess
文件并执行我想要的替换?
What must I do to get my .htaccess
file to be parsed and carry out the substitution I'm after?
我尝试将以下内容放在 C:xamppapacheconfhttpd.conf
:
I have tried placing the following in C:xamppapacheconfhttpd.conf
:
<Directory />
AllowOverride all
Require all allowed
</Directory>
但没有运气.我什至尝试将我的 .htaccess
文件更改为以下内容:
but have had no luck with it.
I have even tried changing my .htaccess
file to the following:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteBase /www.johndoe.com/
RewriteRule ^about/?$ ?value=about
但我仍然收到 404 not found 错误消息.
but I'm still getting the 404 not found error message.
推荐答案
事实证明,使用默认的 XAMPP 配置,不需要 C:xamppapacheconfhttpd.conf
,因此无需重新启动 Apache,因为我们只是对 C:xampphtdocswww.johndoe.com.htaccess
进行更改.作为 这个RewriteBase 上的帖子 解释说,我们不需要 RewriteBase
因为我们不会在目标链接中为 .htaccess
规则使用绝对路径.由于这些目标规则中的相对链接将相对于我们提供服务的目录,因此我们需要从规则中删除 www.johndoe.com
目录,如下所示:
As it turns out, with the default XAMPP configuration there is no need to C:xamppapacheconfhttpd.conf
, hence no need to restart Apache as we are just making changes to C:xampphtdocswww.johndoe.com.htaccess
. As this post on RewriteBase explains, we do not need RewriteBase
since we will not use absolute paths in the destination links for .htaccess
rules. Since relative links in these destination rules will be relative to the directory we are serving out of, we need delete the www.johndoe.com
directory from the rule, as follows:
- 将
.htaccess
放在 ``C:xampphtdocswww.johndoe.com` 中. 将以下重写规则放入其中:
- Place the
.htaccess
in ``C:xampphtdocswww.johndoe.com`. Place the following rewiterule in it:
RewriteEngine on
RewriteRule ^about/?$ index.php?value=about
相关文章