XAMPP .htaccess mod_rewrite not working(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
.htaccessin ``C:xampphtdocswww.johndoe.com`. Place the following rewiterule in it:
RewriteEngine on
RewriteRule ^about/?$ index.php?value=about
这篇关于XAMPP .htaccess mod_rewrite 不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:XAMPP .htaccess mod_rewrite 不工作
基础教程推荐
- php中的PDF导出 2022-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- php中的foreach复选框POST 2021-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- 将变量从树枝传递给 js 2022-01-01
- Web 服务器如何处理请求? 2021-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
