htaccess子域作为变量获取

时间:2022-08-20 11:18:30

I am trying to make like this.

我想这样做。

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=(.*)

I already tried this

我已经试过了

<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>

but it only passing the subdomain not the content parameters value.

但它只传递子域而不是内容参数值。

1 个解决方案

#1


0  

Use this code in your DocumentRoot/.htaccess:

在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] 

#1


0  

Use this code in your DocumentRoot/.htaccess:

在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]