Mamp和RewriteBase(Mamp and RewriteBase)

我使用Mamp免费版。 我想在当地工作。 例如,make链接在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是一种让链接在本地工作的好方法吗? 怎么做?

I use Mamp free version. I want to work local. For instance, make links work inside htdocs/site1 as they were in the root. To test I tried this:

Inside htdocs I have 2 folders: site1 and site2 Inside site1 I have 2 files: file1.php and file2.php Inside site1 I have .htaccess with this:

RewriteBase /site1/

Inside file 1 I have a link to check if I can use absolute link. It does not work:

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

Is RewriteBase a good way to make links work in local?. How to do that?

最满意答案

使链接在htdocs / site1内部工作,因为它们位于根目录中

您将只需要htdocs/.htaccess这个单一规则(高于site1的级别)

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

.htaccess inside site1中你不需要.htaccess inside for this, you can remove that RewriteBase`行。

make links work inside htdocs/site1 as they were in the root

You will just need this single rule in htdocs/.htaccess (a level above site1)

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

You don't need .htaccess insidesite1for this, you can remove thatRewriteBase` line.

Mamp和RewriteBase(Mamp and RewriteBase)

我使用Mamp免费版。 我想在当地工作。 例如,make链接在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是一种让链接在本地工作的好方法吗? 怎么做?

I use Mamp free version. I want to work local. For instance, make links work inside htdocs/site1 as they were in the root. To test I tried this:

Inside htdocs I have 2 folders: site1 and site2 Inside site1 I have 2 files: file1.php and file2.php Inside site1 I have .htaccess with this:

RewriteBase /site1/

Inside file 1 I have a link to check if I can use absolute link. It does not work:

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

Is RewriteBase a good way to make links work in local?. How to do that?

最满意答案

使链接在htdocs / site1内部工作,因为它们位于根目录中

您将只需要htdocs/.htaccess这个单一规则(高于site1的级别)

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

.htaccess inside site1中你不需要.htaccess inside for this, you can remove that RewriteBase`行。

make links work inside htdocs/site1 as they were in the root

You will just need this single rule in htdocs/.htaccess (a level above site1)

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

You don't need .htaccess insidesite1for this, you can remove thatRewriteBase` line.