Forum Topic: Redirecting in Site for other look
I erased all my pages on a domain to work from scratch to develop a new site with a different character, since I have been reading my error files lately, I keep getting 404 errors for pages and directories that dont exist anymore (obvioulsy), so I used a redirectmatch in .htaccess but I keep getting 404s and I think it might be looping or something, not sure.
Heres the code used:
# Redirecting or Redirectmatching RedirectMatch 301 ^/directory1/?$ http://example.com/ RedirectMatch 301 ^/directory2/?$ http://example.com/ RedirectMatch 301 ^/page1\.php?$ http://example.com/ RedirectMatch 301 ^/page2\.php?$ http://example.com/ RedirectMatch 301 ^/staticpage1\.html?$ http://example.com/ RedirectMatch 301 ^/staticpage2\.html?$ http://example.com/
The idea is to let people and search engines to know the pages and directories no longer exist. Is this correct or am I looping somehow.
4 Replies to “Redirecting in Site for other look”
Those rules look fine in terms of looping, but there could be other factors involved, such as other rules, scripts and so forth. Also it depends on the actual 404 pages that are coming thru.. if you would like to provide some examples of requests that you are concerned about, I would be glad to take a look..
That said, you may want to use 410 Gone as a response for pages that are, well, gone. I too have used the "redirect 404 pages to the home page" technique but am unsure as to the effectiveness in terms of overall site SEO. It is recommended to use the 410 response to keep things clear and accurate.
Oh, I see, didnt know about the 410 until I saw an old post here earlier, so it should be like this then:
# Redirecting or Redirectmatching with 410 RedirectMatch 410 ^/directory1/?$ RedirectMatch 410 ^/directory2/?$ RedirectMatch 410 ^/page1\.php?$ RedirectMatch 410 ^/page2\.php?$ RedirectMatch 410 ^/staticpage1\.html?$ RedirectMatch 410 ^/staticpage2\.html?$
Here I dont even mention the domain, am I correct? And can I create a 410 error page for that and include it in the htaccess as well:
ErrorDocument 410 /410.html
.. without disturbing the server (in other words is it ok to create any kind of error pages associated to transfer code messages)?
Also, in regards to the directories, the 410 automatically indicates that the directory in question AND all content inside no longer exists, or should I add additional parameters in that case to indicate all pages contained in the directories are gone?
Hi Leon, great questions!
"Here I dont even mention the domain, am I correct?"
Correct, and you can use an online tool such as one of the following to check that everything is returning as expected:
"..in other words is it ok to create any kind of error pages associated to transfer code messages)?"
Yes, technically it is your prerogative to set up any type of custom error pages, but I would keep them simple and any avoid further redirects just to avoid any confusion with the search engines.
"Also, in regards to the directories, the 410 automatically indicates that the directory in question AND all content inside no longer exists, or should I add additional parameters in that case to indicate all pages contained in the directories are gone?"
This depends on how the rule is written and what is matched. For example using Redirect vs RedirectMatch for a specific directory will result in either the content getting matched or not. So it will vary from rule to rule, but you can always check via one of the tools mentioned above (or similar) to see how the server is responding to various requests.
Thanx for the response Jeff, I tested it myself in different browsers including explorer, chrome, opera and firefox and they all delicoiusly say:
410 Gone - The requested resource /page1.php is no longer available on this server and there is no forwarding address. Please remove all references to this resource.
Exactly the same message on all browsers, I was setting up an error page but you are right, its not a redirect to a custom page which would confuse browsers even more, its just a direct command, Ill wait til tommorrow to see If my error logs are empty finally.
JUST FOR THE RECORD:
For anybody that needs it, I tested all kinds of things so the same line would include a 410 gone in a directory and all its contents (kept gettin 500 server errors) until I found it out....
... if you want to command a 410 gone message for a directory and all subdirectories in it, including all files (so it wont toss a 404 error page instead use this for the directories:
RedirectMatch 410 ^/directory1/?(.*)?$
...and not this:
RedirectMatch 410 ^/directory1/?$
(which would simply take into account only the named directory, not its complete contents nor possible matches below)