htaccess 中的子域重定向[关闭]

2023-11-22

我想知道使用 htaccess 规则是否可以实现以下场景。 我希望将一个子域重定向到另一个网址。 我已联系服务器管理员将“test”子域添加到“example.com”域。 主域没有其他子域。

我必须在 htaccess 中添加什么规则才能实现:http://test.example.com被重定向到http://www.something-else.com.

注意:www.something-else.com 是一个复杂的网址(200 个字符长度)

EDIT我的完整 htaccess 文件现在如下所示:

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

在浏览器地址栏中输入 test.example.com 没有任何效果。白屏,没有重定向,什么也没有。如果那里存在某个页面,我不知道。


对于静态网址:

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(如果原始域有需要移动到其他域的文件夹):

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]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

htaccess 中的子域重定向[关闭] 的相关文章

随机推荐