Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm running a magento installation on an apache server. There are many pages indexed in both google and linked to from external sites.

I can't use 301 redirects in a .htaccess file as I can't be sure I will catch all the links. At the moment all requests are rewritten through magento and if a request isn't found magento returns a 404 File not Found.
Is there a way of using one of the apache modules to filter the response* from magento and if a 404 Not Found is being sent back then replace the response with a standard 301 Redirect to the home page?

E.g.

Request to Magento --> Apache --> Rewrite to Magento index.php page --> page processed.

Response if request exists --> return results (200) if request doesn't exist --> return 404 --> apache filter change response --> return 301 redirect to /

I appreciate any help.

Thanks,

Jon

  • as far as I am aware mod_rewrite is only used to rewrite requests and doesn't allow the modification of responses.
share|improve this question
    
You might want to ask over on webmasters.stackexchange.com but I'm not sure this is a good idea. Instead you should modify your 404 page to have helpful information for someone to find the correct information. If you must do it, you could have magento/php return the 301 directly. –  matthew Feb 28 '11 at 23:03
add comment

1 Answer

mod_rewrite is the answer. it can be used to return a specific response (301 among them) based on a set of conditions - say, wether the requested content exists or not, which will, essentially, result in replacing 404 with 301.

If you provide modre details about your existing config and data, I will be able to give you an example of a specific rewrite rule that will work for you. Otherwise, please refer to Apache's documentation of mod_rewrite - it's quite extensive, alhtough alittle bit dry :)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.