Phil Penny
Phil Penny

Reputation: 123

redirect subdomain but keep URL intact

I am pointing blog.website.com at website.com/blog correctly however I want the URL to remain as blog.website.com

Here is my .htaccess file

RewriteEngine on

RewriteCond %{HTTP_HOST} ^blog\.website\.com$
RewriteRule ^/?$ "http\:\/\/website\.com\/blog" [L]

How can I do this?

UPDATE

I have managed to do it using the following code in my .htaccess file:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^blog\.website\.com$
RewriteCond %{REQUEST_URI} !^/blog/$
RewriteRule (.*) http://website.com/blog/ [P]

However, now my blog images are not showing. If I put them into the blog folder created for the subdomain, they work, but I want to keep them inside the website.com/blog folder, how can I achieve this?

Upvotes: 2

Views: 1329

Answers (1)

anubhava
anubhava

Reputation: 785146

Try this rule instead:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^blog\.website\.com$
RewriteRule !^blog/ blog%{REQUEST_URI} [L]

Upvotes: 1

Related Questions