【发布时间】:2012-12-29 04:24:33
【问题描述】:
我正在尝试将所有流量重定向到子域。
www.example.com、example.com、sub.othersite.com 全部重写到 sub.othersite.com
效果很好。现在我需要排除单个 URL 重定向到子域
所以如果 www.example.com/THE/URI 进来,我希望 mod rewrite 忽略子域重写并将其发送到主域。
看起来很简单,但我无法让它工作,因为我有一个额外的重写,以确保所有域(也有几个停放的域)汇集到一个域中以提供内容。
我还有一些其他的重写条件。它们都列在这里。如果有人能指出我正确的方向 - 我基本上需要这样做:
如果传入请求是针对 /THE/URI 然后去 www.example.com/THE/URI 否则 重写到 sub.othersite.com
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# ignore system folder
RewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 !^(client/*)
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php?/$1 [L]
# if it is the SPECIAL URI redirect and EXIT
RewriteCond $1 !^(/THE/URI)
RewriteCond %{HTTP_HOST} !^www.example.com$
RewriteRule ^(.*)$ http://www.example.com/THE/URI [L]
#catch all other traffic
RewriteCond %{HTTP_HOST} !^example.anothersite.com$
RewriteRule ^(.*)$ http://example.anothersite.us/$1
</IfModule>
【问题讨论】:
标签: apache mod-rewrite subdomain