htaccess重定向所有子域(除了www)以使用参数进行索引

时间:2016-01-21 22:02:45

标签: apache .htaccess redirect

我想做的是:

sub.domain.com

domain.com/index.php?q=sub  

 sub.domain.com/somefile.php

 domain.com/sub/index.php?q=sub&file=somefile.php  

 sub.domain.com/somefile.php?m=12&r=12

 domain.com/sub/index.php?q=sub&file=somefile&m=12&r=12  

并使用子域保留地址栏。

我得到了一些代码,但它并没有远远地做我需要的东西,所以任何帮助都会非常感激 谢谢!

1 个答案:

答案 0 :(得分:1)

RewriteEngine On


#Rewrite foo.domain.com/foo/bar to /index.php?q=foo&page=foobar
#in the condition pattern bellow, we match against any http_host string that doesnt start with www
RewriteCond %{HTTP_HOST} ^((?!www).+)\.domain\.com$ [NC]
#if the above condition is met, the rewrite the request
RewriteRule ^(.*)$ /index.php?q=%1&file=$1 [QSA,NC,L]