I’m currently using dotcloud hosting for an application and I’m redirecting my naked url using my domain registrar namecheap (through “@” hostname and “*” hostname as a URL direct- and then a cname for www to dotcloud)
This works well for re-directing people back to main www.
My issue is I want to map the visitor to the equivalent naked domain url they were trying to visit. E.g. http://example.com/websitepage1 to http://www.example.com/websitepage1. Right now visiting any page on the site minus the “www” will just redirect you to the homepage.
Any ideas or suggestions?? I’d prefer not to switch out of dotcloud hosting for the moment but will do so if it’s impossible to get this to work another way.
Thanks!
UPDATE
The urls that need to be redirected are created dynamically so it’s not impossible to hard code them. The DNS doesn’t have to be namecheap. I can put the nameservers else where if there is an option that allows redirect of naked urls to the www equivalent. Any ideas appreciated!
Given their documentation (0), it seems possible to do the following 301/302 redirects using Namecheap’s forwarding options:
- Setup a naked domain redirect from
example.com
towww.example.com
- Setup a naked domain redirect with a url from
example.com/url/ to
www.example.com/url/`
I don’t see in the documentation where it says they support a wildcard option, so for every url you’d like to support, it seems you may have to create a forwarding entry.
You need to add rewrite rules to nginx.conf:
server {
server_name hostname.org;
rewrite ^(.*) http://www.hostname.org$1 permanent;
}
You can specify custom rewrite rules (and actually almost any Nginx setting) by creating a file named nginx.conf at the top of your app. http://docs.dotcloud.com/0.9/guides/nginx/