htaccess中的子域重定向 [英] subdomain redirection in htaccess
问题描述
我想知道使用htaccess规则是否可能出现以下情况. 我希望将一个子域重定向到另一个URL. 我已经联系服务器管理员,将"test"子域添加到"example.com"域. 主域没有其他子域.
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.
我必须在htaccess中设置什么规则才能实现: http://test.example.com 重定向到
What rule must i put in htaccess to do achieve: http://test.example.com to be redirected to http://www.something-else.com.
注意:www.something-else.com是一个复杂的网址(长度为200个字符)
NOTE: www.something-else.com is a complicated url (200 chars length)
编辑 我的完整htaccess文件现在看起来像:
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]
htaccess文件位于example.com根目录. 我没有物理访问测试子目录,尽管我知道它存在-对该URL的ping显示我example.com的IP
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
在浏览器的地址栏中键入test.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.
推荐答案
对于静态网址:
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]
对于动态url(如果原始域的文件夹需要移动到另一个域):
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]
根据您的修改:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^test.example.com$ [NC]
RewriteRule ^(.*)$ redir.php [R=301,NC,L]
这篇关于htaccess中的子域重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!