Forum Moderators: phranque

Message Too Old, No Replies

Faking a subdomain with mod-rewrite/htaccess?

         

neophyte

1:44 am on Jun 1, 2015 (gmt 0)

10+ Year Member



Hello All –

I’m not sure if this can be done with mod-rewrite and htaccess but here’s what I’m after:

I’ve got a CMS driven project under development that serves all pages (frontend and backend) via mod-rewrite in my htaccess file.

Frontend pages are triggered via a URI such as www.example.com (frontend home page); www.example.com/accommodations, etc.

Backend pages are triggered via a URI such as www.example.com/private (backend CMS login page), www.example.com/private/members, etc.

What I’d like to do is remove the “private” from the backendURI and use a subdomain-like trigger such as: www.private.example.com (which would serve the backend CMS login page), www.private.example.com/members, etc.

To be clear, I don’t want to actually create a subdomain… all I want to do is create a “private” trigger of sorts linked to the host name which would be trapped by mod-rewrite which I can then just parse through a PHP script.

Is there a way to do this… or something like this?

All advice/guidance greatly appreciated

lucy24

6:13 am on Jun 1, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I don’t want to actually create a subdomain

Whether you like it or not, you are creating a subdomain. That's what "private.example.com" means. Nothing can happen without a DNS pointing to the right place; it isn't a matter of "Send everyone to example.com and let them handle it from there".

:: insert boilerplate about servers' stubborn refusal to operate in more than two dimensions ::

So the first step is to find out whether your host supports wild-card subdomains. Most do. Once things are set up with a suitable (physical) directory structure, you can make your script handle subdomains any way you like.

If you're using a big-name CMS, the subdomain capablity is probably already built in, so make sure you're not reinventing the wheel.

neophyte

7:33 am on Jun 1, 2015 (gmt 0)

10+ Year Member



Hi Lucy -

Thanks for your advise... will check with my hosting company as advised