【问题标题】:Hide index.php in subdirectory after rewrite (lighttpd)重写后隐藏子目录中的 index.php (lighttpd)
【发布时间】:2016-01-20 13:18:41
【问题描述】:

现在如何设置

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

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 上,这会导致我网站的 url 像这样重写

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

驾驶舱网址实际上是相同的:

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

我在调查什么 所以我一直在考虑为 lighttpd 留下 apache,并且我一直在搞乱他们的 mod_rewrite 语法和配置,但我遇到了一个问题,即驾驶舱 url 并不完全干净。这就是我在 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 一样摆脱 url 的 index.php 部分,但我无法让它正常工作。

有人对此事有任何想法吗?

【问题讨论】:

    标签: apache .htaccess mod-rewrite lighttpd


    【解决方案1】:

    我认为您可能试图过度思考这一点。 像下面这样的重写规则可能更接近您正在寻找的内容。

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

    【讨论】:

    • 可悲的是,我已经尝试过了,但它不起作用。由于某种原因,Lighttpd 仍然匹配第二个正则表达式,因此重写到 /index.php 而不是 /cockpit/index.php
    • 这些规则有几个缺陷,首先,路径前应该有一个^;其次,.+ 最好替换为 .* 以使 /cockpit/ 匹配。
    猜你喜欢
    • 2012-09-07
    • 1970-01-01
    • 2016-08-08
    • 2014-06-17
    • 2011-02-12
    • 2017-02-21
    • 2016-09-22
    • 2023-03-11
    • 2015-07-21
    相关资源
    最近更新 更多