简体   繁体   中英

htaccess redirecting specific URL to new domain

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

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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