Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess redirect main domain but not sub subfolder

I was wondering how to exclude a subfolder from .htaccess redirect.

I have an .htaccess file in the root of my old domain and I have the following in it:

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L] 

This of course redirects any traffic from the old domain to the new one. But I want to exclude a directory from this rule. Meaning www.olddomain.com/media/videos should not redirect to www.newdomain.com/media/videos

The reason I want the exclusion is because I'm hosting static files such as videos on a shared web server (old domain) and I'm keeping everything else the site needs on the new VPS server (new domain).

like image 909
user546585 Avatar asked Jun 21 '12 19:06

user546585


1 Answers

Just put RewriteCond %{REQUEST_URI} !^/media/videos above your RewriteRule. It checks wether the URL starts with /media/videos and if it does so, the RewriteRule will not be met.

like image 144
Christopher Avatar answered Sep 23 '22 01:09

Christopher