重写规则以处理url异常

时间:2012-05-21 17:52:07

标签: apache .htaccess mod-rewrite

我有一个服务于许多网站的应用程序,我使用Apache mod-rewrite来映射 url是这样的

http://site1.net/controller
http://site2.net/controller2/another_view
http://site3.net/
http://special_case.net/

映射到:

index.php?url=http://site1.net/controller
index.php?url=http://site2.net/controller2/another_view
index.php?url=http://site3.net/
index.php?url=http://special_case.net/hub

我的重写规则是:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

除了特殊的最后一种情况外,我需要强制处理所有情况 在处理特定域时使用称为“hub”的控制器。我在这个项目上与其他人合作,这意味着一旦调用索引文件,我就无法对路由做任何事情。

有人可以修改我的规则,以便解决上述所有问题吗?

2 个答案:

答案 0 :(得分:1)

您当前的规则似乎没有将主机名添加到url get-parameter。所以我将其添加到以下内容中:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteCond %{HTTP_HOST} ^(special_case\.net)$
RewriteRule ^(.*)$ index.php?url=http://%1/hub/$1 [QSA,L]

RewriteCond %{HTTP_HOST} ^(.*)$
RewriteRule ^(.*)$ index.php?url=http://%1/$1 [QSA,L]

答案 1 :(得分:-1)

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^http://special_case.net index.php?url=http://special_case.net/hub [QSA,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
相关问题