XAMPP的mod_rewrite的.htaccess不工作 [英] XAMPP .htaccess mod_rewrite not working

查看:1178
本文介绍了XAMPP的mod_rewrite的.htaccess不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行XAMPP的Windows版5.6.11。我有以下PHP文件:

I am running XAMPP for Windows 5.6.11. I have the following PHP file:

C:\xampp\htdocs\www.johndoe.com\index.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

化为或者是以下两种:

as either of the following two:

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:\ XAMPP的\ apache的\的conf \ httpd.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:\ XAMPP的\ apache的\的conf \ httpd.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未找​​到错误消息。

but I'm still getting the 404 not found error message.

推荐答案

事实证明,用默认的XAMPP配置中,没有必要 C:\ XAMPP的\ apache的\的conf \ httpd.conf文件,因此没有必要重新启动Apache,因为我们仅仅做修改 C:\ XAMPP \ htdocs中\ www.johndoe.com \的.htaccess 。作为<一个href="http://(http://stackoverflow.com/questions/21347768/what-does-rewritebase-do-and-how-to-use-it)">this张贴的RewriteBase 的解释,我们不需要的RewriteBase ,因为我们不会在目的地链接的.htaccess 规则。由于这些目标的规则相对链接是相对于我们所服务出来的目录,我们需要删除该规则的 www.johndoe.com 目录,如下所示:

As it turns out, with the default XAMPP configuration there is no need to C:\xampp\apache\conf\httpd.conf, hence no need to restart Apache as we are just making changes to C:\xampp\htdocs\www.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:\ XAMPP \ htdocs中\ www.johndoe.com`
  • 将在它下面的rewiterule:

  • Place the .htaccess in ``C:\xampp\htdocs\www.johndoe.com`.
  • Place the following rewiterule in it:

RewriteEngine on
RewriteRule ^about/?$ index.php?value=about

这篇关于XAMPP的mod_rewrite的.htaccess不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆