I am trying to use .htaccess to handle the 404s but for some reason the default page CMS/indes/noRoute keeps interfering, is there a way to change magento's 404 using .htaccess instead of that default no-route, the idea is to send the 404s a search result containing the keywords they were looking for. I got it to work on other sites before but on magento they have a strange way of handling 404s and I don't know how to get around it.
One possible way to do this is by rewriting the Mage_Core_Controller_Varien_Router_Default class, which is doing the redirect to noroute. You could redirect to your own controller, which is showing the search results.
Yes sure you can do it with .htaccess.
Please try the following code in your .htaccess file.
ErrorDocument 404 http://demowebsite.com/custom404error.php
The custom404error.php can be whatever webpage you want to display as your 404 error. This trick worked for me.
Related
I'm doing this to fix an error with my AMP pages. I'm using the Automatic AMP plugin, and this plugin lets you access the AMP pages using 2 different methods
site.com/post/amp/
site.com/post/?amp
Using the AMP Page validator (https://validator.ampproject.org) I see that all AMP pages using just /amp/ get multiple errors, while /?amp is validated correctly.
Unfortunately, Google is checking /amp/ for all my pages, hence I'm getting tons of errors.
What I'd like to know is how to use the .htaccess redirect rule to add the ? to the AMP queries so all /amp/ requests are redirected (with a 301) to /?amp/
I'd appreciate suggestions on this. Thank you
Something like this:
RewriteEngine on
RewriteRule ^(.*)/amp/$ /$1?amp [R=301,L]
This will redirect any URL ending in /amp/ to the same but with ?amp instead, which seems to be what you want. To go in your root .htaccess file.
I have the following code in my htaccess file to handle 404 codes:
ErrorDocument 404 https://www.mywebsite.co.uk/lost.php
RewriteEngine On
And of course a custom 404 page is returned (works fine).
I did a nibbler check and it said the following:
It is a common mistake to setup missing page handling by using a
redirect. The missing page should directly return a 404 error and not
redirect to another page.
This website does not return a 404 error HTTP status code for missing
pages. This is bad because search engines like Google might mistake
this for a real page of content.
What is the best practice to handle 404 error codes if the above is no good? I am just wanting something generic that is a catch all. No need to use a 301 because the point of my 404 is just to let visitors know that what they are looking for is not there or they have made a typo.
If it is a "common mistake" to to use a redirect how should it be done?
Thank you for any help.
You need to remove https:// or http:// from 404 handler otherwise it forces Apache to do a full redirect instead of internal rewrite.
So you can use:
ErrorDocument 404 /lost.php
It depends. If you have an application running on the webserver that takes in every URL coming in and has some logic implemented, that by itself has to figure out if the URL exists, then the application should directly return a 404 error page under the given URL and not redirect to another page like 404.html or so. But if your webserver handles the url requests with the .htaccess file then it is OK to setup a document that is returned in case of an invalid URL.
I've got a fairly simple web site in which I trap any 404 errors and one that's started coming through is trying to access /home/sycamore/public_html/...valid url... instead of /...valid url...
Obviously /home/sycamore/public_html/ is the file path to where the site lives but firstly, how on earth is this request being generated. I can find nothing in my code that does anything like that and yet it is happening in just one area that;s been recently added. Any idea what can caused this?
In an attempt to avoid this I've added a rule to the .htaccess file so it now starts
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^/home/sycamore/public_html/(.*)$ /$1 [R,L]
However, this doesn't appear to do anything, I'm still getting the 404 reported on /home/sycamore/public_html/...valid url... although there are many other rewrite and redirect rules in .htaccess which work perfectly.
Any ideas as to (1) why the problem might be there in the first place and (2) why my htaccess attempt to 'correct' the url is failing?
I would also add that most of the requests for this URL are coming from search bots; google, yahoo, etc. and there is no mention of /home/... in the sitemap.xml file.
I'm pretty sure the original cause was down to some redirects in the htaccess file which were redirecting to a non-existent page and, I assume, causing it to generate this sort of error.
Still no idea why the attempted fix to rewrite the url didn't work but hopefully mending the htaccess file will have got rid of a lot of the problems (though there are still some unaccounted ones).
I have a site submitted to google webmaster tools that I helped a family member redevelop. The site is great and working but google says 4 old url's displayed crawl errors and return 404 errors.
From what i've read this is common when using CMS systems and page alias's get changed. However, while I have access to the php and .htaccess files and I can see that mod rewrite is on I don't know how to implement a 301 redirect. I'm not familiar with php code.
The 4 url's google says are errors I can't even find, so I don't know where they are being linked from. For example this is one of the errors:
mywebsite.co.uk/index.php?page=kitchens (which produces a 404 error page)
should link, or redirect to,
mywebsite.co.uk/kitchens-northampton/
I noticed this code in the htaccess file if it's of any relevance:
RewriteRule ^(.+)$ index.php?page=$1
I just don't know what it means. Can anyone offer some advice?
Thank you.
I'm totally lost here, I have several Magento installations where the backend url doesn't work nice.
The problem is this:
In the frontend, all urls are perfectly rewritten so index.php is not in the url and mod_rewrite works.
but for the admin part, all urls that are created have the index.php part still in there, in a normal installation it wouldn't be a problem put now, a url like index.php/admin/dashboard results in a 404 error page. But, the funny part is that when I remove the index.php part of the url, it works.
I fixed this problem with a few .htacces tricks and hacks, but I find these hacks no good. Some parts of the backend still won't work or need their own .htacces redirect, or won't work at all even with the redirect in .htacces.
So, my questions are: Why are my Magento installations giving 404 errors on a index.php/admin call? And how to nicely get rid of the index.php part in the backend urls, without .htacces hacks?
The Magento version for all shops is 1.7.0.2
The solution is very simple, add "AcceptPathInfo On" to apache configuration.
Credits: http://www.magentocommerce.com/answers/discussion/178/index.phpinstall-was-not-found/p1