Angelin
Angelin

Reputation: 648

htaccess internal redirect from subdomain to root

I want to redirect internally everything from static.domain.com to www.domain.com. Please note that static.domain.com is an existing subdomain, I don't want to use wildcards. I've used this code in the subdomain's .htaccess

RewriteCond %{HTTP_HOST} ^static\.domain\.com
RewriteRule ^(.*)$ http://domain.com/$1 [R=301]

but i get the error:

Forbidden

You don't have permission to access / on this server.

Thanks in advance!

Edit: in my root i have an index.php that handles my application framework.

it looks like this:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rt=$1 [L,QSA]

My static subdomain contains only a .htaccess file that looked exactly like this:

RewriteCond %{HTTP_HOST} ^static\.domain\.com
RewriteRule ^(.*)$ http://domain.com/$1 [R=301]

I added RewriteEngine On and now it redirects me externally (if i request static.domain.com/css/style.css it takes me to domain.com/css/style.css). I would like to redirect internally (the address in the browser shouldn't change).


Solution

Studied a bit the apache RewriteRule Flags and found the solution. I used the P flag for proxy. Here is the .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^static\.outletika\.com
RewriteRule ^(.*)$ http://outletika.com/$1 [R=301,P]

Upvotes: 2

Views: 1407

Answers (1)

Angelin
Angelin

Reputation: 648

This is the correct solution:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^static\.outletika\.com
RewriteRule ^(.*)$ http://outletika.com/$1 [R=301,P]

Upvotes: 1

Related Questions