alanj1998
alanj1998

Reputation: 41

Redirecting subdomain without changing URL using .htaccess

wondering if you can help me with some .htaccess.

I want to have sub.example.com display data from example.com/sub without changing the URL : ie. sub.example.com will stay sub.example.com although it is reading from example.com/sub

I have the following data in .htaccess:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub.example.com
RewriteRule ^(.*)$  http://example.com/sub/$1 [L,NC,QSA]

I tried to change the [L,NC,QSA] to [P] but I get an error 403 - forbidden access.

Any help would be appreciated!

Upvotes: 1

Views: 281

Answers (1)

Trueman
Trueman

Reputation: 274

RewriteCond %{HTTP_HOST} ^sub.example.com [NC]
RewriteRule ^(.*)$ http://example.com/sub/$1 [L,R=301]

Upvotes: -1

Related Questions