Ice
Ice

Reputation:

.htaccess Rewrite Rules for subdomain

I use codeigniter as my main install on the main domain. I have created a subdomain and a folder called live e.g. live.domain.com maps to public/live . However in public I use codeigniter.

I now have the dynamic codeigniter url:

http://domain.com/api/

which I want to map to my subdomain:

https://live.domain.com

So going to:

https://live.domain.com/api/functioname

would be using the script:

http://domain.com/api/apifunctioname

and possibly:

http://domain.com/api/apifunctioname/parameter1/parameter

Everything is on the same server so no redirects are needed.

Anyone have any ideas on which rewrite rules to use?

Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^live\.domain\.com [NC]
RewriteRule (.+)$ "http://domain.com/api/$1" [L]

The above works great as a rewrite but redirects to http://domain.com/api/functionname instead I want it to route; so that when going to:

https://live.domain.com/api/functioname

It stays at that url but uses the script of

http://domain.com/api/functionname

Thank you very much,

Ice

Upvotes: 8

Views: 16039

Answers (2)

Just add index.php, see below

RewriteEngine On
RewriteCond %{HTTP_HOST} ^live\.domain\.com$ [NC]
RewriteRule (.+)$ "https://domain.com/index.php/api/$1" [L,P]

Upvotes: 4

Simon B. Jensen
Simon B. Jensen

Reputation: 978

How about something like the following:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^live\.domain\.com$ [NC]
RewriteRule (.+)$ "https://domain.com/api/$1" [L,P]

Upvotes: 10

Related Questions