Htaccess redirect all files from subdirectory in one domain to another domain
16,969
This should work in one .htaccess file at primary.com
root directory:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.primary\.com [NC]
RewriteRule ^apples/(.*) http://www.secondary.com/$1 [R=301,NC,L]
![AnchovyLegend](https://i.stack.imgur.com/7qHj7.jpg?s=256&g=1)
Author by
AnchovyLegend
Updated on June 04, 2022Comments
-
AnchovyLegend about 2 years
I am trying to create a permanent htaccess redirect (301) from all files in one directory in one domain, to another domain as follows:
Redirect all files in the following directory:
http://www.primary.com/apples/*
To:
http://www.secondary.com
I am not very experienced with htaccess and was wondering if someone can assist me in creating this redirect?
Many thanks in advance!
-
Avatar almost 9 yearsSeems to work, just wondering why you are using
(.*)
instead of(.*)$
. -
Felipe Alameda A almost 9 yearsIn this particular case there is no need for that anchor, although it could be added. Makes no difference. Htaccess regex is based on PCRE so there is no risk of getting stuck in an infinite loop. Check this link to get more information.