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

I have a wildcard subdomain *.domain.com assigned to public_html/.

I want to make the directory www.domain.com/folder1/index.php?name=rock to rock.domain.com.

As for another one, I want to make www.domain.com/folder1/folder2/index.php?id=5 to 5.domain.com

Are there any way to do this? I'm a beginner in mod-rewrite. Really appreciate your help. Thanks

Additional Information

I need both of them. They will have different variables.

For example, /folder1/index.php is based on state name(?state=statename).

For the /folder1/folder2/index.php, it will be based on unique name(?name=uniquename).

So, www.domain.com/folder1/index.php?state=statename will be statename.domain.com

and www.domain.com/folder1/folder2/index.php?name=uniquename will be uniquename.domain.com

Thank you

See Question&Answers more detail:os

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

1 Answer

In the htaccess file in your document root, you can add rules specific for "rock" and "5":

RewriteEngine On

RewriteCond %{HTTP_HOST} ^rock.domain.com$ [NC]
RewriteRule ^$ /folder1/index.php?name=rock [L,QSA]

RewriteCond %{HTTP_HOST} ^5.domain.com$ [NC]
RewriteRule ^$ /folder1/folder2/index.php?name=5 [L,QSA]

If you want it to redirect in the other direction then you'd need:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^state=(.*)$ 
RewriteRule ^folder1/index.php$ http://%1.domain.com/? [L,R=301]

RewriteCond %{QUERY_STRING} ^name=(.*)$ 
RewriteRule ^folder1/folder2/index.php$ http://%1.domain.com/? [L,R=301]

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

548k questions

547k answers

4 comments

86.3k users

...