0

I am working on one application in which admin creates sub-domain or folder with help of coding. It will look like following.

http://www.example.com/folder-name/
http://folder-name.example.com/

Its like multisite concept with same code base for different sub-domains.

Now what i need is that with help of htaccess i need to use code of root folder so when we open any of above link it will take me to http://www.example.com/index.php?id=xx. I am trying to work this with .htaccess but not getting any result and main thing should be in browser it must say any of above link only. Can anyone have idea how to do this?

Martin
  • 22,212
  • 11
  • 70
  • 132
Tejas P Mehta
  • 69
  • 1
  • 7

2 Answers2

1

You can use this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(folder-name)\. [NC,OR]
RewriteCond %{REQUEST_URI} ^/(folder-name)/ [NC]
RewriteRule ^ /index.php?id=xx [L,QSA]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • had to add RewriteBase /document_root but apart from that it works. Thank you for solution. Just a question, can we make it more dynamic? like if i have 20-25 new folders than can i use some special settings for (folder-name) in both lines? But it should not work for other folders like JS, IMAGES, CSS, CLASSFILES, etc. – Tejas P Mehta Feb 17 '15 at 06:46
  • If css, js, image files are in separate folders then you can have an exclusion rule using `RewriteCond %{REQUEST_URI} !^/(css|js|images)/ [NC]` condition – anubhava Feb 17 '15 at 07:51
0

A quick search of google found this which should give you some direction.

Community
  • 1
  • 1
  • This link has helped some now only thing is that i want to work with folders. like http://www.example.com/folder-name/ Link has example of subdomains. – Tejas P Mehta Feb 16 '15 at 11:35