I’m having difficulty running my .htaccess file within my Ghost droplet. I have an .htaccess file with the following commands to redirect non-www requests to www requests, but a redirect is not happening:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
I also tried the nginx server workaround, but got a continuous loop error with the redirect script and have a CNAME with www and mywebsitedomain. Any thoughts as to why this redirect isn’t happening?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
As @jsamuel mentioned, the Ghost One-Click droplet uses the Nginx web server which doesn’t use .htaccess files. In order to direct non-www requests to www, you can update Nginx’s configuration. One the Ghost droplet, you can find that in /etc/nginx/sites-enabled/ghost You’ll want to add a new server block that returns a 301 redirect from the non-www domain to the www one. It would look like this:
server {
listen 80;
server_name example.com;
return 301 http://www.example.com$request_uri;
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name www.example.com;
client_max_body_size 10G;
location / {
proxy_pass http://localhost:2368;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
}
}
Sorry @asb it worked as you had said. Sorry for so many questions and thank you for your help!
I believe the Ghost server image uses only Nginx, not Nginx in front of Apache, so you can’t use Apache’s .htaccess files. You’d have to make your changes in the Nginx configuration.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.