问题
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