Mosa
Mosa

Reputation: 21

redirect public_html folder

I have two domain name

I have 3 folders inside the public_html (www) folder

i want a wildcard using htaccess code to redirect the domain name to folder2 so it be like this:

www.domain.com/  =>  public_html/folder2/
www.domain.com/forum  => public_html/folder2/forum
www.domain.com/support =>  public_html/folder2/support

or even subdomains:
www.forum.domain.com  => public_html/folder2/forum
www.support.domain.com  =>  public_html/folder2/support
www.[*random*].domain.com  =>  public_html/folder2/

with www. and without it

and the same for www.parked.com to folder3

and any attempt to access folder1 through e.g. www.domain.com/folder1 it then search for folder1 only inside folder2 not inside public_html .

i will deeply appreciate the help

regards

Upvotes: 0

Views: 8986

Answers (1)

moskito-x
moskito-x

Reputation: 11968

Some of your wishes

.htaccess

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)forum.domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/folder2/forum/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^(www\.)support.domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/folder2/support/$1 [R=301,L]

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

EDIT:

So, if the input is the url

www.domain.com/index.html you will be redirect to

www.domain.com/folder2/index.html

The Condition

RewriteCond %{HTTP_HOST} ^(www\.)domain.com [NC]

means:

If there is "domain.com" in %{HTTP_HOST} do the rule

RewriteRule ^(.*)$ http://www.domain.com/folder2/$1 [R=301,L]

means:

  • $1 is a variable. If the request was for http://example.com/foo/bar, then %1 would contain example.com and $1 would contain foo/bar.

You see this page it is a good explanation

  • For EVERY Test in your browser don't forget to clear the browser-cache

Upvotes: 1

Related Questions