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]
Share:
16,969
AnchovyLegend
Author by

AnchovyLegend

Updated on June 04, 2022

Comments

  • AnchovyLegend
    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
    Avatar almost 9 years
    Seems to work, just wondering why you are using (.*) instead of (.*)$.
  • Felipe Alameda A
    Felipe Alameda A almost 9 years
    In 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.