How to set domain 301 redirects?


How to set domain 301 redirects?
The domain 301 redirect
I use discourse_docker

(Johnathan Nader) #2

Anyone figured this out?

(Mittineague) #3

Are you sure you need to?

The routing in Discourse uses the topic id (eg. 19976 for this topic) so if changes are made in the title and / or category links go to the right topic automatically.

Are you seeing Warning or Error messages anywhere?

(Joe Seyfried) #4

I guess the OP meant a redirect from to - not an internal 301 redirect. That should be an nginx related question.

(Sam Saffron) #5

The general gist here is to add a after_web hook that would amend nginx conf so it redirects, or maybe lay down a new file in conf.d for the redirect.

(Joe Seyfried) #6

Haven’t tried it, but my guess would be that if you take the solution from this question

into the server section of your conf.d/discourse.conf file, you should be fine (so start after the listen directive, overwrite the server_name, and put the redirect there). Note that you have to re-apply this when you rebuild your container (correct me if I’m wrong, @riking).

(Kane York) #7

You would do it in an

in your app.yml file, so the change is reapplied on rebuild.

Check out web.ssl.template.yml for an example of how to do that.

(Johnathan Nader) #8

So I edit this, and put this into it?

server {
    #listen 80 is default
    return 301 $scheme://$request_uri;

And then have to also update the app.yml file?

And then restart/rebuild it?

(Kane York) #9

Nope, that would be nginx -t followed by service nginx restart. Assuming you’re using a second nginx outside the container.

If you aren’t using that, you need a pups replace rule and a rebuild.


I’m dense and slow. What am I adding where in a Digital Ocean droplet install to get rid of the dreaded “Redundant Hostnames” error in Google Analytics?

(Kane York) #11

Follow the instructions here:

then, on the outer nginx, add this:

file: /etc/nginx/conf.d/redirect-from-silly-domain.conf
server {
    listen 80;
    listen [::]:80;
    return 301$request_uri;


Even in Digital Ocean installs? I don’t think there is a /etc/nginx/conf.d to mess with. I’ve looked and no nginx directory in there.

(Kane York) #13

You need to apt-get install nginx and set it up first, as discussed in that topic, and if conf.d doesn’t exist use /etc/nginx/sites-enabled .


Roger that, just did the deed thanks. Redirect now works.