Dino Geek, try to help you

How to do 301 redirection for non-existing pages?


To do a 301 redirection for non-existing pages, you need to configure your web server to redirect these pages to a new, valid URL. A 301 redirect indicates that a page has permanently moved to a new location, which helps in maintaining search engine rankings and improving user experience by guiding visitors to active pages instead of showing error messages.

Here’s a step-by-step approach for handling 301 redirections on Apache and Nginx, two of the most commonly used web servers:

  1. Apache

1. Edit the `.htaccess` file: Locate the `.htaccess` file in the root directory of your website. If you don’t have this file, you can create one.

1. Add Redirect Rule: Use the following syntax to create a 301 redirect: \`\`\`apach Redirect 301 /old-page.html http://www.yourwebsite.com/new-page.html \`\`\` For non-existing pages, you can redirect all 404 errors to a specific page by adding: \`\`\`apache ErrorDocument 404 /404.html Redirect 301 /404.html http://www.yourwebsite.com/new-page.html \`\`\`

1. Save and test: After saving the `.htaccess` file, test the redirection by accessing the non-existing page in a web browser to ensure it correctly redirects to the specified URL.

  1. Nginx

1. Edit the server block configuration file: Open the configuration file for your site, typically located in `/etc/nginx/sites-available/` or similar directory depending on your setup.

1. Add Redirection Rule: Insert the following lines to create a redirection for a non-existing page: \`\`\`nginx server { listen 80; server\_name yourwebsite.com www.yourwebsite.com;

location / { try\_files $uri $uri/ /404.html; } error\_page 404 /404.html; location = /404.html { internal; return 301 http://www.yourwebsite.com/new-page.html; } } \`\`\`

1. Save and reload Nginx: Save your changes and reload Nginx to apply the new configuration: \`\`\`sh sudo systemctl reload nginx \`\`\`

  1. Examples:
    - If the page `/old-blog-title` no longer exists, redirecting it to `/new-blog-title` ensures that those arriving at the old URL are seamlessly transferred to the new content.
    - For e-commerce sites, redirecting a discontinued product page like `/product-123` to a new product `/product-456` maintains potential sales that could be lost via a 404 error.

  1. Reliable and Recognized Sources:

1. Apache HTTP Server Documentation:
- [URL Rewriting Guide](https://httpd.apache.org/docs/current/rewrite/)
- [mod_alias – Redirect](https://httpd.apache.org/docs/2.4/mod/mod_alias.html#redirect)

1. Nginx Documentation:
- [NGINX: A 301 Redirect for Non-existing Pages](https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/)

1. Google Search Central Blog:
- [Managing a Blog: Moving from One URL to Another](https://developers.google.com/search/blog/2008/04/managing-blogger-workarounds-moving)

By implementing these 301 redirections, your website will gracefully handle requests for non-existing pages, ensuring a smooth user experience and preserving SEO equity.


Simply generate articles to optimize your SEO
Simply generate articles to optimize your SEO





DinoGeek offers simple articles on complex technologies

Would you like to be quoted in this article? It's very simple, contact us at dino@eiki.fr

CSS | NodeJS | DNS | DMARC | MAPI | NNTP | htaccess | PHP | HTTPS | Drupal | WEB3 | LLM | Wordpress | TLD | Domain name | IMAP | TCP | NFT | MariaDB | FTP | Zigbee | NMAP | SNMP | SEO | E-Mail | LXC | HTTP | MangoDB | SFTP | RAG | SSH | HTML | ChatGPT API | OSPF | JavaScript | Docker | OpenVZ | ChatGPT | VPS | ZIMBRA | SPF | UDP | Joomla | IPV6 | BGP | Django | Reactjs | DKIM | VMWare | RSYNC | Python | TFTP | Webdav | FAAS | Apache | IPV4 | LDAP | POP3 | SMTP

| Whispers of love (API) | Déclaration d'Amour |






Legal Notice / General Conditions of Use