0

I have two domain name

  • www.domain.com
  • www.parked.com

I have 3 folders inside the public_html (www) folder

  • folder1
  • folder2
  • folder3

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

Mosa
  • 21
  • 1
  • 4

1 Answers1

1

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
moskito-x
  • 11,832
  • 5
  • 47
  • 60
  • thanks for the reply and basically what i meant is a wildcard to redirect any subdomain to folder2 and domain.com to folder2... – Mosa Jul 27 '12 at 02:06
  • that's what it does. Redirect any domain.com to **"//www.domain.com/folder2 !**" – moskito-x Jul 27 '12 at 02:11
  • yh sorry to confuse you :S but i wanted it to read `www.domain.com/folder2/index.html` as `www.domain.com/index.html` and ignores the `index.html` page inside `public_html` – Mosa Jul 27 '12 at 08:15