最近我们更改了子域的名称,现在我们需要将所有旧页面重定向到新的子域页面。
示例页面链接:
旧网址:http://jquery.webcodehelpers.com/2013/08/what-does-dollar-sign-means-in-jquery.html
新网址:http://uieiq.webcodehelpers.com/2013/08/what-does-dollar-sign-means-in-jquery.html
我的发现:当我尝试访问顶级子域时,它运行良好。
如何将旧子域上的所有 URL 重定向到新子域?
目前我的.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]
最佳答案
通过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]
请阅读:Apache mod_rewrite Introduction
关于regex - 如何在 .htaccess 中从一个子域重定向到另一个子域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19323366/