动态子站点htaccess的(而不是重定向)而不是、重定向、站点、动态

2023-09-02 09:36:17 作者:哥、不愿将就

目前,我使用htaccess的有一个网址系统是这样的:

Currently, I'm having an url system like this by using the htaccess:

- www.domain.com/member/username
- www.domain.com/member/username/contact
- www.domain.com/member/user/album/title-of-the-album/albumID

......这样的事情

.. something like that

下面是我的htaccess的,它完美地工作。

Here is my htaccess, and it worked perfectly.

RewriteRule ^member/([a-zA-Z0-9_-]+)$   member.php?username=$1
RewriteRule ^member/([a-zA-Z0-9_-]+)/contact$   contact.php?username=$1
RewriteRule ^member/([a-zA-Z0-9_-]+)/album/([a-zA-Z0-9_-]+)/([0-9]+)$   album.php?username=$1&title=$2&album_id=$3

现在我想建立一个动态的子域名系统的用户,喜欢username.domain.com 所以我决定用下面的htaccess的:

Now I want to setup a dynamic subdomain system for the user, likes "username.domain.com" So I decided to used the below htaccess:

RewriteCond %{HTTP_HOST} !^www.domain.com
RewriteCond %{HTTP_HOST} ([^.]+).domain.com [NC]
RewriteRule ^(.*)$ www.domain.com/member/%1 [L]

但是,这将用户重定向,而不​​是www.domain.com/member/username他们的旧域www.domain.com/member/username 我想保持username.domain.com(没有URL在地址栏的变化)的用户服务。

But this redirect the user to their old domain "www.domain.com/member/username" instead of "www.domain.com/member/username" I want to keep the user stay in "username.domain.com" (no url change in the address bar).

如果可能的话,是否有任何机会,以保持相同的结构等新的URL,当我输入,如:

If possible, is there any chance to keep the same structure for other new url, such as when I type:

在username.domain.com/contact将载入www.domain.com/member/username/contact(在地址栏中没有URL变化)内容 在username.domain.com/album/title-of-the-album/albumID将载入www.domain.com/member/username/album/title-of-the-album/albumID的内容(在地址栏中没有URL变化)

请帮助!

推荐答案

尝试:

RewriteCond %{HTTP_HOST} !^www.domain.com
RewriteCond %{HTTP_HOST} ([^.]+).domain.com [NC]
RewriteRule ^/?$ /member.php?username=%1 [L]

RewriteCond %{HTTP_HOST} !^www.domain.com
RewriteCond %{HTTP_HOST} ([^.]+).domain.com [NC]
RewriteRule ^/?contact$ /contact.php?username=%1 [L]

RewriteCond %{HTTP_HOST} !^www.domain.com
RewriteCond %{HTTP_HOST} ([^.]+).domain.com [NC]
RewriteRule ^/?album/([a-zA-Z0-9_-]+)/([0-9]+)$ /album.php?username=%1&title=$1&album_id=$2 [L]