【问题标题】:unextected redirection un xampp for windowsxampp for windows 中的意外重定向
【发布时间】:2014-10-16 22:22:53
【问题描述】:

我正在创建一个网站,在将网站上传到虚拟主机之前,我在 Windows 上使用 XAMPP。我试图使用搜索引擎友好的 URL,例如:

http://localhost/mysite/[something]
to
http://localhost/mysite/index.php?p=[something]

我试过这个.htaccess

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([0-9A-Za-z]+) index.php?id=$1 [QSA,L] #and also tried http://localhost/mysite/index.php?p=$1

在此之前,我尝试了更多示例,但没有奏效。真正的问题是,例如,如果 y 类型

localhost/mysite/some_page

我收到一个错误 (403),使用 [R] 标志我意识到重定向是:http://localhost/C:/XAMPP/htdocs/mysite/index.php?p=some_page

我删除了 htaccess 文件并重新启动了 apache,但问题仍然存在一些 url

【问题讨论】:

  • ^([0-9A-Za-z]+) 不会匹配 /mysite/something。尝试将其简化为^(.*)$,看看会发生什么。

标签: php windows apache redirect xampp


【解决方案1】:

也许我正在尝试解决一个不同的问题,但如果 [something] 总是导致您的 index.php 提供的内容,那么只需将所有请求发送到 index.php 并让该页面使用 URL 字符串来获取提供正确内容所需的变量(即 / 之后的字符串)。

您可能需要在 .htaccess 中使用 Options -MultiViews 关闭 MultiViews。

以下是您在 .htaccess 中需要的内容

RewriteBase /
# Where "/" is the location of your index.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA, L]

希望这会有所帮助。

【讨论】:

  • 我的问题是我得到一个重写/重定向地址为 localhost/C:/XAMPP/blablabla
  • 啊,简单。您需要将 RewriteBase 设置为 index.php 文件的位置,即 RewriteBase /
猜你喜欢
  • 2018-06-21
  • 2021-06-28
  • 2015-08-23
  • 1970-01-01
  • 2010-10-18
  • 1970-01-01
  • 1970-01-01
  • 2018-05-02
  • 2012-05-31
相关资源
最近更新 更多