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

5
  • RewriteCond %{HTTP_HOST} ^www\.one.abcd\.com$ RewriteRule ^/?$ "http\:\/\/abcd\.com\/pages\/one" [R=301,L] Commented May 20, 2015 at 6:58
  • basically you can add rule in your htaccess file to achieve this Commented May 20, 2015 at 6:59
  • 1
    Related stackoverflow.com/questions/10642426/… Commented May 20, 2015 at 7:06
  • do you have any other rules in htaccess? Commented May 20, 2015 at 7:51
  • have this RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php?/$0 [PT,L] Commented May 20, 2015 at 7:52

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

can u plz write the above rules specifically for one.abcd.com also actually my regex knowledge is very poor
@Uttara it works for one.abcd.com, and two.abcd.com, and anything.abcd.com except www
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 just replace [^.]+ with one
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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.