htaccess 中的子域重定向 [英] subdomain redirection in htaccess

查看:39
本文介绍了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 被重定向到 http://www.something-else.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 根目录.我没有对 test 子目录的物理访问权限,尽管我知道它存在 - ping 那个 url 会显示 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.

推荐答案

对于静态 url:

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]

来自您的

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

这篇关于htaccess 中的子域重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆