1

I have a single CI application hosted in say abcd.com
and it has different pages like

  • abcd.com/pages/one
  • abcd.com/pages/two
  • abcd.com/pages/three

now the requirement is when user access one.abcd.com as url (in address bar) then it will display abcd.com/pages/one content

EDIT : but the url in address bar should remain one.abcd.com

similarly two.abcd.com should display abcd.com/pages/two content

how that can be achieved ? as routing only accept the path name excluding domain

Uttara
  • 2,496
  • 3
  • 24
  • 35

1 Answers1

2

Try adding these rules to the htaccess file in your document root:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?abcd\.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.abcd\.com$ [NC]
RewriteRule ^/?$ /pages/%1 [L]

This will only work if you have *.abcd.com all pointing to the same document root.

Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • can u plz write the above rules specifically for `one.abcd.com` also actually my regex knowledge is very poor – Uttara May 20 '15 at 07:17
  • @Uttara it works for one.abcd.com, and two.abcd.com, and *anything*.abcd.com except www – Jon Lin May 20 '15 at 07:18
  • yeah I know you have written the generic rule but just can u plz write it for specific one, and also I have pointed my subdomains to same IP as that of domain, but it shows 403 forbidden – Uttara May 20 '15 at 07:22
  • @Uttara just replace `[^.]+` with `one` – Jon Lin May 20 '15 at 07:23
  • its not working :( as I have pointed my `one.abcd.com` to same root folder as `abcd.com` hence when accessing `one.abcd.com` it displays the website from start, also plz look at my EDIT – Uttara May 20 '15 at 07:54