views:

3336

answers:

1

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

+1  A: 

How about something like the following:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^live\.domain\.com$ [NC]
RewriteRule (.+)$ "https://domain.com/api/$1" [L,P]
Simon Jensen
Thank you however I tried that but I just got a 404 Not Found - very peculiar
I should probably mention that it is untested. Have you tried incresing the mod_rewrite loglevel, and analyzed what exactly is going on?
Simon Jensen
You should have "^live\.domain\.com" as the RewriteCond, and there should be a second RewriteCond checking for /api/ URLs.
Tomalak
I've been searching my server but cant find the log files anywhere; I've been looking for rewrite.log
Also when I set RewriteLogLevel 3 in the .htaccess I get a 500 error
@Tomalak: Agreed, he should definitely do that.@Ice: You can specify the log file with the RewriteLog-directive.
Simon Jensen
@jensen I tried that but receive a 500 error; also with some Twitter help I identified the rewrite problem; removing ^/ fixes it however I am not trying to rewrite the url but to map it on to it
Could you possibly post what you've ended up with so far?
Simon Jensen
@jensen I have updated my post
Instead of [L] as flags to RewriteRule, try [L,P], iirc, that should perform a proxy request internally.
Simon Jensen
Thank you; however the change led to a 404 not found
Do you have mod_proxy enabled?
Simon Jensen
@jensen Brilliant! It had to enable mod_proxy and mod_proxy_http but yup then it worked! :D
Thank you very much!
@jensen One more question; is there a way to make it only work for https://
I found it:RewriteCond %{HTTPS} =on