2014-01-18 82 views
1

我想這樣做。htaccess子域與獲取變量

user.mydomain.com -> mydomain.com/user.php?user=user 
user.mydomain.com/content_(.*).xhtml -> mydomain.com/user.php?user=user&content=(.*) 
user.mydomain.com/content_(.*).xhtml?get=(.*) ->mydomain.com/user.php?user=user&content=(.*)&get=(.*) 

我已經嘗試過這個

<Directory "/var/www/html"> 

RewriteEngine On 


# host doesn't start with www 
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteCond %{HTTP_HOST} !^m\. [NC] 

# host starts with something else 
RewriteCond %{HTTP_HOST} ^([^\.]+)\.mydomain\.com$ [NC] 

# rewrite 
RewriteRule ^(.*)$ users.php?user=%1 
RewriteRule ^users\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^content_(.*).xhtml$ users.php?user=%1&content=$1 [L,QSA] 
</Directory> 

,但它只有通過子域而不是內容的參數值。

回答

0

使用此代碼在您的DocumentRoot/.htaccess

RewriteEngine On 

RewriteRule ^users\.php$ - [L] 

RewriteCond %{HTTP_HOST} !^(?:www|m)\. [NC] 
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ [NC] 
RewriteRule ^$ /users.php?user=%1 [L,QSA] 

RewriteCond %{HTTP_HOST} !^(?:www|m)\. [NC] 
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ [NC] 
RewriteRule ^content_([^.]+)\.xhtml$ /users.php?user=%1&content=$1 [L,QSA,NC] 
+0

由於它的工作原理:) :) – user3210116