如何使用mod_rewrite执行此操作

时间:2011-09-05 05:26:11

标签: apache mod-rewrite

我需要满足两个条件才能使用mod_rewrite执行特定的操作:

  • admin.something.com应该访问某些内容:/ admin(应该是某些内容的访问者)
  • anythingelse.something.com应该去某些东西/index.php?school=anythingelse,应该知道某些事情。

我认为(/希望)这很简单,但我完全不了解mod_rewrite。任何帮助将不胜感激。谢谢!

3 个答案:

答案 0 :(得分:0)

有效的事情

RewriteEngine on

RewriteCond %{HTTP_HOST} ^admin.something.com$
RewriteRule ^(.*)$ http://something.com/admin [L]

RewriteCond %{HTTP_HOST} !^something.com$
RewriteRule ^(.*)$ http://something.com/index.php?school=$1 [L]

答案 1 :(得分:0)

RewriteEngine On
RewriteCond %{HTTP_HOST} ^admin\.something\.com
RewriteRule ^(.*)$ /admin/$1 [L]

RewriteCond %{HTTP_HOST} !^something.com$
RewriteRule ^(.*)$ /index.php?school=$1 [L]

答案 2 :(得分:0)

RewriteCond %{HTTP_HOST} ^admin\.something\.com
RewriteRule .* http://something.com/admin [L,R=301]

我会在php代码中将subdomain.something.com重定向到something.com/index.php?school=subdomain,例如

header('Location: something.com/index.php?school='.$retreived_from_http_host_subdomain);

因为我不知道如何在RewriteRule内获取域名(也许有人会在这里发布答案)