htaccess how to redirect subdirectory to external URL

Go To StackoverFlow.com

5

I tried:

//301 Redirect Old File
Redirect 301 www.mydomain.com/subdirectory http://newurl.com

but that lands me at newurl.com/subdirectory, which doesn't exist.

2012-04-05 18:43
by miles
I've asked this before and scoured the web for an answer and come up with nothing. I'm assuming this cannot be done with htaccess. Guess PHP will have to do - miles 2012-04-05 18:59


11

Enable mod_rewrite and .htaccess then add this code in your .htaccess under DOCUMENT_ROOT:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteRule ^subdirectory/?$ http://newurl.com [L,R=301,NC]
2012-04-05 19:26
by anubhava
This would go in the htaccess file inside the subdirectory, correct - miles 2012-04-12 14:32
No in your main .htaccess under DOCUMENT_ROO - anubhava 2012-04-12 15:53
Ads