Apache RewriteRule到子文件夹

时间:2014-12-19 22:33:33

标签: php apache .htaccess mod-rewrite

我正在尝试将所有请求重定向到文件夹到子文件夹。这方面的一个例子是openbay:https://github.com/isohuntto/openbay/blob/master/.htaccess

我的文件夹如下所示:

Main/
└── src
    ├── app
    └── public
        ├── index.php

我想要做的是当你转到Main文件夹时,你会转到公共文件夹中找到的index.php和其他文件一样。

我试过这个:

RewriteEngine on

RewriteRule ^(.*)$ src/public/$1

导致内部服务器错误(500),并在apache日志中说:

[Fri Dec 19 22:53:26.447255 2014] [core:error] [pid 3497] [client 127.0.0.1:37913] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

我能做些什么来让它表现得像我想要的那样?

1 个答案:

答案 0 :(得分:2)

您可以通过添加将跳过重写有效文件或目录的RewriteCond来避免无限循环。用这个替换你的规则:

DirectoryIndex index.php
RewriteEngine on

RewriteRule ^(index\.php)?$ src/public/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ src/public/$1 [L]
相关问题