简体   繁体   English

如何在.htaccess中从一个子域重定向到另一个子域?

[英]How can I redirect from one subdomain to another in .htaccess?

Recently we changed the name of a subdomain, now we need to redirect all the old pages to the new subdomain pages. 最近,我们更改了子域的名称,现在我们需要将所有旧页面重定向到新的子域页面。

Example page links: 页面链接示例:

My findings: when I try to access the subdomain in the top level it is working good. 我的发现:当我尝试访问顶级子域时,它运行良好。

How can I redirect all URLs on the old subdomain to the new subdomain? 如何将旧子域上的所有URL重定向到新子域?

currently i have the below code in .htaccess file , please guide to solve the problem 目前我在.htaccess文件中有以下代码,请指导解决问题

RewriteEngine on
RewriteCond %{HTTP_HOST} ^jquery\.webcodehelpers\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.jquery\.webcodehelpers\.com$
RewriteRule ^/?$ "http\:\/\/uieiq\.webcodehelpers\.com\/search\/label\/jquery\ interview\ questions" [R=301,L]

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your DOCUMENT_ROOT/.htaccess file: 通过httpd.conf启用mod_rewrite.htaccess ,然后将此代码放入DOCUMENT_ROOT/.htaccess文件中:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^jquery\.webcodehelpers\.com$ [NC]
RewriteRule ^ http://uieiq.webcodehelpers.com%{REQUEST_URI} [L,R=301,NE]

Please read: Apache mod_rewrite Introduction 请阅读: Apache mod_rewrite简介

This worked for me, and maintains the URI: 这为我工作,并维护URI:

RewriteCond %{HTTP_HOST} ^jquery\.webcodehelpers\.com
RewriteRule (.*)$ http://uieiq.webcodehelpers.com/$1 [R=301,L]

I used this to redirect a subdomain to another subdomain. 我用它来将一个子域重定向到另一个子域。

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

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