How do I force the WWW-NON redirect
If you want to add a WWW to NON-WWW redirect, we've got some code for the most common webservers and technology.
Apache
Check out your .htaccess file (or httpd.conf / apache2.conf for global settings)
Look for ErrorDocument and if it isn't there, try adding something like this:
ErrorDocument 404 /custom-404.html
Apache will now look for a page called custom-404.html and display that with the status code 404.
NGINX
For NGINX we want to take a look at the server block in /sites-available
server {
listen 80;
server_name example.com;
error_page 404 /custom-404.html;
location = /custom-404.html {
internal;
root /path/to/your/pages;
}
}
The lines we want to focus on are error_page below which tell NGINX that the custom-404.html page is the 404 page and to return that with a 404 status code.
Microsoft IIS
IIS is a little different as you get to use the GUI!
- Open IIS Manager and navigate to your website.
- In the Features view, double-click "Error Pages".
- In the Actions pane, click "Add" to add a new error page or click "Edit" to modify an existing error page.
- Enter 404 as the status code, and set the path to your custom error page.
- Make sure to choose the option to return the custom error page with a 404 status code.
After you've changed it
Remember to restart your web server and head over to Little Warden to check that it's responding correctly!