Reputation: 3060
I have a Django website running on Heroku where most of the data is served via AJAX. In order to allow search engines to index those pages I want to serve requests with the _escaped_fragment url parameter using phantomjs running on a separate nodejs server. similar to this on apache:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=(.*)$
RewriteRule (.*) http://webserver:3000/%1? [P]
(source: http://backbonetutorials.com/seo-for-single-page-apps/)
` How can I do this in Heroku?
Upvotes: 0
Views: 173
Reputation: 11888
Heroku does not give you control over the frontend loadbalancer (which is where you'd ideally want this embedded). You would need to embed this logic into your application (See: Middleware), or run your own "mini loadbalancer" in front of your application (i.e. you would run nginx on each web worker, purely to implement this match and redirect scheme).
To use nginx, the fastest way is to use https://github.com/ryandotsmith/nginx-buildpack
$ heroku config:set BUILDPACK_URL=https://github.com/ddollar/heroku-buildpack-multi.git
.buildpacks
$ echo 'https://github.com/ryandotsmith/nginx-buildpack.git' >> .buildpacks
$ echo 'https://github.com/heroku/heroku-buildpack-python.git' >> .buildpacks
$ git commit .buildpacks -m 'Add multi-buildpack'
[uwsgi]
http-socket = /tmp/nginx.socket
master = true
processes = 4
die-on-term = true
memory-report = true
module = yourapp.wsgi:application
env = DJANGO_SETTINGS_MODULE=yourapp.settings
/tmp/app-initialized
when it starts upNow obviously this is pretty heavy modification, and will take a while to get it set up right. If you don't really need this high-performance option, take the simpler route and set up a custom middleware layer instead.
Upvotes: 2