How can I redirect everything but the index as 410?

How can I redirect everything but the index as 410? - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the How can I redirect everything but the index as 410? error on your web browser. Problem :


Our site shut down and we need to give a 410 redirect to the users. We have a small one-page replacement site set up in the same domain and a custom 410 error page. We'd like to have it so that all page views are responded with 410 and redirected to the error page, except for the front page, which should point to the new index.html.



Here's what in the .htaccess:



RewriteEngine on
RewriteCond %REQUEST_FILENAME !-f
RewriteRule !^index.html$ index.html [L,R=410]


This works, except for one thing: If I type the domain name, I get the 410 page.



With www.example.com/index.html I see the index page as I should, but just www.example.com gets 410. How could I fix this?


Solution :

If I follow what you're trying to do, I think this would work.



RewriteEngine on
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule .* - [L,G]


If the resource doesn't exist (is not either a file or a directory) send the 410.



Create a page called maintenance.html (or whatever file extension necessary for your server side language of choice) and then use this code:



<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %REQUEST_URI !/maintenance.html$ [NC]
RewriteCond %REQUEST_URI !.(jpe?g?|png|gif) [NC]
RewriteRule .* /maintenance.html [R=410,L]
</IfModule>


This will always show maintenance.html regardless of which page they request in their browser.


We hope that this article has helped you resolve the apache, htaccess, redirects error in your web browsers. Enjoy browsing the internet uninterrupted!

Comments

Popular posts from this blog

Redirected urls show in serp, with the original permalink but with the title and meta of the target page

How do I redirect traffic only if being accessed from a specific port?