简体   繁体   English

想要重定向到通配符子域而不使用.htaccess更改url

[英]Want to redirect to wildcard subdomain without changing url using .htaccess

I want to redirect a wildcard sub-domain without changing the url. 我想在不更改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. 例如,如果用户键入subdomain.domain.com,我希望它转到www.domain.com/subdomain,但不要更改原始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. 我尝试了许多示例来使其工作,并提出了以下htaccess代码以重定向到通配符子域。 This code will re-direct user to proper wildcard subdomain but the resulting url does not change. 此代码会将用户重定向到正确的通配符子域,但结果URL不变。 If user types in subdomain.domain.com the url changes to www.domain.com/subdomain. 如果用户键入subdomain.domain.com,则网址将更改为www.domain.com/subdomain。

I'm on a shared hosting plan with GoDaddy and I have a dedicated IP. 我正在与GoDaddy共享托管计划,并且拥有专用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. 这就是我最初在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'. 在尝试了下面的建议答案并输入subdomain.domain.com之后,我现在被引导到看起来像内部GoDaddy屏幕的屏幕,上面写着“很酷的未来家”。 What kind of changes to do I need to make to my htaccess or is what I'm asking for even possible? 我需要对htaccess进行哪些更改,或者什至有可能要求什么?

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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