Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

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]

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

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

  • "username.domain.com/contact" will load the content of "www.domain.com/member/username/contact" (no url change in the address bar)
  • "username.domain.com/album/title-of-the-album/albumID" will load the content of "www.domain.com/member/username/album/title-of-the-album/albumID" (no url change in the address bar)

Please help !!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
604 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try:

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]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...