htaccess redirecting specific URL to new domain

江枫思渺然 提交于 2021-02-11 15:29:45

问题


I'm getting myself seriously confused with Rewrite Conditions and Rewrite Rules in my htaccess file.

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.

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).


回答1:


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]


来源:https://stackoverflow.com/questions/33471648/htaccess-redirecting-specific-url-to-new-domain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!