htaccess将特定的URL重定向到新域 [英] htaccess redirecting specific URL to new domain
问题描述
我让自己严重困惑于htaccess文件中的重写条件和重写规则.
I'm getting myself seriously confused with Rewrite Conditions and Rewrite Rules in my htaccess file.
基本上,我有一个新域,并且想将我的文章重定向到新域.例如,在有人访问old-domain.com/article/XYZ-article-title时,我希望它重定向到new-domain.com/article/XYZ-article-title.
Basically I have a new domain and want to redirect my articles to the new domain. For instance in someone visits old-domain.com/article/XYZ-article-title I want it to redirect to new-domain.com/article/XYZ-article-title.
让我感到困惑的是,仅当/article在域中时才希望它重定向(旧域仍在用于其他内容).
Where I'm getting myself confused is that I only want it to redirect if /article is in the domain (the old domain is still in use for other stuff).
推荐答案
您可以在 DOCUMENT_ROOT/.htaccess
文件中使用以下代码:
You can use this code in your DOCUMENT_ROOT/.htaccess
file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?old-domain\.com$ [NC]
RewritRule ^article(/.*)?$ http://new-domain.com%{REQUEST_URI} [NC,R=301,L]
这篇关于htaccess将特定的URL重定向到新域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!