.htaccess mod_rewrite子域名

时间:2012-07-04 02:50:42

标签: .htaccess mod-rewrite

htaccess的:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^site\.com$ [NC]
RewriteRule ^(.*)$ http://www.site.com/$1 [L,R=301]
RewriteRule ^new/?$ index.php?section=new

这很好用,但我最近实现了一个子域m.site.com,它读取了/mobile目录。访问m.site.com/new时,除了返回服务器错误外,它不会显示任何内容。我该怎么做才能解决这个问题?

基本上,我想要http://m.site.com/new

达到与http://www.site.com/new

相同的效果

1 个答案:

答案 0 :(得分:1)

您可以将m.site.com指向/,然后点击:

RewriteEngine On
RewriteBase /


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^site\.com$ [NC]
RewriteRule ^(.*)$ http://www.site.com/$1 [L,R=301]

# here i added [L] flag to stop rules matching
RewriteRule ^new/?$ index.php?section=new [L]

# everything that is not in new/* will still get redirected to the "old" mobile site
RewriteCond %{HTTP_HOST} ^m\.site\.com$
RewriteRule (.*) /mobile/$1 [L,QSA]