Reputation: 8106
I need to setup a directive in my .htaccess file to redirect as follows:
from http://mydomain.com/internal/
to http://myotherdomain.com/internal/
Can anyone assist?
Thanks
MY CODE -- PRODUCES 500 INTERNAL SERVER ERROR
//Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.com/internal[nc]
RewriteRule ^(.*)$ http://myotherdomain.com/internal/$1 [r=301,nc]
Upvotes: 0
Views: 251
Reputation: 2057
Try this:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mydomain.com$ [NC]
RewriteRule ^internal(.*)$ http://myotherdomain.com/internal$1 [L,NC]
The (.*)
will copy anything so you can use it in $1
. If the redirect should be permanent, just add R=301
after L,NC
Edit Your mistakes in the given piece of codes are:
^mydomain.com$
[NC]
RewriteRule ^(.*)$ http://myotherdomain.com/$1
OR RewriteRule ^internal/(.*)$ http://myotherdomain.com/internal/$1
, but your Rule will redirect to internal/internal
Upvotes: 1
Reputation: 8218
You had a few issues with your file: Comments start with #
not //
, you can't match the URI with HTTP_HOST (you were trying to match /internal), and there needs to be a space between the rule or cond and the flags (NC). This should work though:
#Rewrite to www
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.com$ [NC]
RewriteRule ^internal(.*)$ http://myotherdomain.com/internal$1 [R=301,NC]
Upvotes: 2