【发布时间】: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