简体   繁体   中英

Want to redirect to wildcard subdomain without changing url using .htaccess

I want to redirect a wildcard sub-domain without changing the url. For example, If user types subdomain.domain.com I want it to go to www.domain.com/subdomain but not change the original url. Both domain and subdomain are in root folder.

I have tried many examples to get this working and have come up with the below htaccess code to redirect to a wildcard sub-domain. This code will re-direct user to proper wildcard subdomain but the resulting url does not change. If user types in subdomain.domain.com the url changes to www.domain.com/subdomain.

I'm on a shared hosting plan with GoDaddy and I have a dedicated IP. This is the makeup of my root folder:

Root->
domain -> subdomain1, subdomain2 etc
domain2
domain3
domain4
.htaccess
welcome.html

The subdomain folders are created using code when the user requests to create there own site. This is what I had tried originally in my htaccess.

Options +FollowSymLinks
RewriteEngine on 
RewriteCond %{HTTP_HOST} !^(www)\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com [NC]
RewriteRule (.*) http://www.domain.com/%1 [NC]

After trying the suggested answer below and typing in subdomain.domain.com I am now directed to what looks like an internal GoDaddy screen that says 'Future home of something quite cool'. What kind of changes to do I need to make to my htaccess or is what I'm asking for even possible?

Have you tried just:

Options +FollowSymLinks
RewriteEngine on 
RewriteCond %{HTTP_HOST} !^(www)\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com [NC]
RewriteCond %1#$1 !^([^#]+)#\1
RewriteCond %{DOCUMENT_ROOT}/%1/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/%1/$1 -d
RewriteRule ^(.*)$ /%1/$1 [L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM