【问题标题】:Mamp and RewriteBaseMamp 和 RewriteBase
【发布时间】:2016-09-02 12:53:17
【问题描述】:

我使用 Mamp 免费版。我想在当地工作。例如,使链接在 htdocs/site1 中工作,就像它们在根中一样。为了测试我尝试了这个:

在 htdocs 中,我有 2 个文件夹:site1 和 site2
在 site1 我有 2 个文件:file1.php 和 file2.php
在 site1 内,我有 .htaccess:

RewriteBase /site1/

在文件 1 中,我有一个链接可以检查是否可以使用绝对链接。它不起作用:

<a href="/file2.php" >go to file 2</a>

RewriteBase 是使链接在本地工作的好方法吗?该怎么做?

【问题讨论】:

  • 你在哪里放置 .htaccess ?在site1目录?
  • 是的,.htaccess 在 site1 内
  • 所以你到底需要什么,按链接时这样说你期望site1/file2.php还是什么?
  • 我尝试让链接在本地工作。因此,我在 file1.php 中放置了一个绝对链接,我希望它转到 file2.php。请记住 file2.php 在 htdocs/site1 中。

标签: php .htaccess mod-rewrite mamp


【解决方案1】:

使链接在 htdocs/site1 中像在根目录中一样工作

您只需要htdocs/.htaccess 中的这条规则(高于site1 的级别)

RewriteEngine On

RewriteRule ^((?!site1/).*)$ site1/$1 [NC,L]

您不需要.htaccess insidesite1for this, you can remove thatRewriteBase` 行。

【讨论】:

  • 您的解决方案是在本地工作的好方法。我试过了,它有效。另一方面,您知道为什么我的 RewriteBase /site1/ 解决方案不起作用吗?也许我不太了解 RewriteBase ?
  • RewriteBase 仅用于 RewriteRule 指令,它本身不会影响您的 URL。
  • 我不明白你的回答。问题是,为什么这个链接不起作用:go to file 2 if there are RewriteBase /site1/
  • 请注意我写的评论。 RewriteBase 不影响 href 链接。我无法在评论部分粘贴大量文本,所以我真诚的建议是阅读 RewriteBase 上的 apache 文档。
猜你喜欢
  • 1970-01-01
  • 2013-05-17
  • 2013-08-27
  • 2020-06-21
  • 1970-01-01
  • 2011-04-15
  • 2017-07-17
  • 2019-11-01
  • 2015-11-16
相关资源
最近更新 更多