mod rewrite - Deploy Django REST API to api.example.com: Apache 2.2, mod_wsgi and mod_rewrite -


i have been searching information on topic couple days , keep running road blocks.

i have django web site , application running @ www.example.com , i'm forcing https. it's deployed on apache 2.2 wsgi. works fine , works both example.com , www.example.com.

i have rest api (pip install djangorestframework) running @ https://www.example.com/api/v1/. works fine.

i want run api subdomain https://api.example.com , keep url in address bar. example, fetch json objects might use this:

curl -x https://api.example.com/objects/ -h 'authorization: token xxx' 

i can using this:

curl -x https://www.example.com/api/v1/objects/ -h 'authorization: token xxx' 

i have separate ssl certificate subdmain , has been correctly configured.

i have tried many things in apache configuration accomplish failed @ every turn. thought use mod_rewrite silently fetch content https://www.example.com/api/v1/ while leaving https://api.example.com in address bar. possible? here i've tried (in sites-available virtual host file):

rewriteengine on rewritecond %{http_host} ^api.example.com [nc] rewriterule ^(.*)$ https://www.example.com/api/v1/$1 [l] 

i have tried several variations of idea no avail. played around https on/off no real benefit.

i read couple places using mod_proxy accomplish when went down road, api available (after quite bit of tweaking) @ desired url (https://api.example.com) none of static content there , when clicked on relative link in django rest framework ui, i'd 404s because looking at:

https://api.example.com/api/v1/

which django complained about: /api/v1/api/v1/

i guess i'm trying make https://api.example.com base url api if https://www.example.com/api/v1/.

duplicate lead discovery of django-hosts package:

django subdomain configuration api endpoints

i have been playing around , shows promise, although haven't "solved" problem yet. plan edit answer once more information share. in meantime, if has used django-hosts approach original question, please add answers here or @ least make comments!


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -