我想这样做。
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 :(得分: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]