subdomain redirection in htaccess [closed]

三世轮回 提交于 2019-12-14 03:40:22

问题


I was wondering if the following scenario is possible using htaccess rules. I want one subdomain to be redirected to another url. I have contact the server admin to add the "test" subdomain to "example.com" domain. The main domain has no other subdomains.

What rule must i put in htaccess to do achieve: http://test.example.com to be redirected to http://www.something-else.com.

NOTE: www.something-else.com is a complicated url (200 chars length)

EDIT My full htaccess file now looks like:

Options +FollowSymLinks
RewriteEngine on
RewriteOptions inherit
RewriteBase /

RewriteCond %{HTTP_HOST} ^test.example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/redir.php [L]

RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

The htaccess file is located to example.com root directory. I have no physical access to test subdirectory, although i know it exists - ping to that url shows me the IP of example.com

Typing test.example.com to the browser's address bar has no effect. White screen, no redirection, no nothing. If some page exists there, i know not.


回答1:


For static urls:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^test.example.com$ [NC]
RewriteRule ^(.*)$ https://www.somdomain.com/a/folder1/somepage?var=xxx&var2=xxx&var3=xxx&var4=http://another-domain.com/folder1/xxxxx/?&var5=xxx&var6=xxxx [R=301,NC,L]

For Dynamic urls (if the original domain has folders that needs to be moved to the other domain):

RewriteEngine On
RewriteCond %{HTTP_HOST} ^test.example.com$ [NC]
RewriteRule ^(.*)$ https://www.somdomain.com%{REQUEST_URI} [R=301,NC,L,QSA]

From your edit:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^test.example.com$ [NC]
RewriteRule ^(.*)$ redir.php [R=301,NC,L]


来源:https://stackoverflow.com/questions/8383284/subdomain-redirection-in-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!