通配符apache mod_rewrite

时间:2011-04-22 21:33:27

标签: apache mod-rewrite wildcard

我正在尝试编写一个mod_rewrite来像这样工作

  • domain.com => index.php
  • anything.anotherdomain.com => index.php/anything
  • foo.blabla.com => index.php/foo
  • wildcard.maybeanother.com/bar/bla => index.php/wildcard/bar/bla

这是我的配置,但是apache只会抛出500错误。

<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{HTTP_HOST} ^*\.*
    RewriteRule ^(*\.*)$ index.php/$1/$2 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php/$1 [L]

</IfModule>

有人知道这有什么问题吗? : - )

提前致谢!

1 个答案:

答案 0 :(得分:1)

尝试一下:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+\.[^.]+$
RewriteRule ^$ index.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+\.[^.]+$
RewriteRule ^(.*)$ index.php/$1 [L]  

RewriteCond %{HTTP_HOST} ^([^.]+)\.[^.]+\.[^.]+\.[^.]+$
RewriteRule ^$ index.php/%1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^([^.]+)\.[^.]+\.[^.]+\.[^.]+$
RewriteRule ^(.*)$ index.php/%1/$1 [L]