我有以下mod_rewrite规则
RewriteCond %{HTTP_HOST} !^(host)\.doamin\.com [NC] RewriteCond %{HTTP_HOST} !^(www)\.domain\.com [NC] RewriteRule ^(.*) /magento/$1 [L]
我需要在nginx上工作,而且我一直在靠墙敲门,以使其工作
谢谢!
UPDATE!
这是对我正在尝试做的更好的解释
store1.domain.com store2.domain.com
所以用户可以进入store1.domain.com/products/url将保持在那里
我们在apache中这样做
RewriteCond %{HTTP_HOST} !^(host)\.domain\.com [NC] RewriteCond %{HTTP_HOST} !^(www)\.domain\.com [NC] RewriteRule ^(.*) /magento/$1 [L]
我们也有一个dns catchall,将所有* .domain.com发送到默认的apache虚拟主机。 我正在靠墙敲着头,让它在nginx中工作,以保持主机名相同,但在幕后重写magentoparsing域。
这是我有,但它只是继续追加/ magento / magento / magento到最后,直到它杀死循环
if ($http_host !~ "^www.domain\.com$") { rewrite ^.+ http://$http_host/magento/$uri last; break; }
上面的问题是不断重写它
store1.domain.com/magento/ store1.domain.com/magento/magento/ store1.domain.com/magento/magento/magento/ and so on
这是一个错误日志
2009/11/03 15:40:26 [error] 22347#0: *2 rewrite or internal redirection cycle while processing "/magento//magento//magento//magento//magento//magento//magento//magento//magento//magento//magento//catalogsearch/advanced/result/", client: 127.0.0.1, server: laptop, request: "GET /catalogsearch/advanced/result/?featured=1 HTTP/1.1", host: "store1.domain.com"
尝试这样的事情:
server { listen 80; server_name *.domain.com ; rewrite ^.+ httр://$host/magento/$uri last; break; }
UPD:
您也可以排除主机名,并已经通过位置+ if +正则expression式在server {}部分完成redirect
location !~ \/magento\/ { if ($host !~ "^(www|host)\.domain\.com$") { // Here goes your rewrite } }
PS。 我认为这可以做更多的性感使用2 server {}块,但我懒得现在想想=)