重写后隐藏index.php在子目录中(lighttpd)

时间:2016-01-20 13:18:42

标签: apache .htaccess mod-rewrite lighttpd

现在如何设置

我有一个网站设置为干净的网址,使用apache mod_rewrite,如下所示:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L,QSA]

该网站还使用名为Cockpit的CMS,它位于我的公共目录下,其中包含类似.htaccess文件的干净网址:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]

在这两种情况下,RewriteEngine On也存在(当然)。

现在在apache上,这导致我的网站的网址被重写为

http://domain.com/a
http://domain.bom/b

并且驾驶舱网址几乎相同:

http://domain.com/cockpit/a
http://domain.com/cockpit/b

我正在研究什么 所以我一直在考虑将apache放在lighttpd后面,我一直在使用mod_rewrite语法和配置搞砸了很多但是我遇到了一个问题,即驾驶舱网址并不完全干净。这就是我在lighttpd上设置它的方法:

$HTTP["host"] == "domain.com" {
        server.document-root = "/var/www/domain.com/public_html"
        index-file.names = ( "index.php" )
        $HTTP["url"] =~ "^(\/cockpit)(\/[a-zA-Z0-9\.]*)*$" {
                url.rewrite-if-not-file = ( "^(.*)$" => "/cockpit/" )
        } else $HTTP["url"] !~ "^(\/cockpit)(\/[a-zA-Z0-9\.]*)*$" {
                url.rewrite-if-not-file = ( "^(.*)$" => "/index.php" )
        }
}

此配置设置有效但驾驶舱网址现在是:

http://domain.com/cockpit/index.php/a
http://domain.com/cockpit/index.php/b

我想像apache那样摆脱网址的index.php部分,但是我无法让它正常工作。

有关此事的任何想法吗?

1 个答案:

答案 0 :(得分:1)

我想你可能会想过这个想法。 像下面这样的重写规则可能更接近您所寻找的内容。

url.rewrite-if-not-file = (
    "/cockpit/(.+)" => "/cockpit/index.php$1",
    "(.+)" => "/index.php$1"
)