Hi all,
I have a PHP5/Zend Framework 1.8.1 web site which is located at:
http://www.example.com/foo
The older version of this site, which infuriatingly, is still maintained by google's index was located at:
http://www.example.com/foo/DEFAULT.ASP
So a lot of people are requesting the above link and hitting a dead end.
I figure, the way to fix this would be to issue a 301 redirect to take him to the new site. The two ways to do this that spring to mind are:
The first way I thought of was to add a rewrite rule to our .htaccess . Our site implementation is PHP5 / Zend Framework 1.8.1, so there's an existing rewrite rule in the .htaccess (as per Zend Framework MVC requirement) which is:
RewriteRule !\.(js|ico|gif|jpg|png|css|jpeg)$ index.php
As a mod_rewrite noob, I did a bit of googling and came up with the following to handle the redirect:
RewriteCond %{HTTP_HOST} ^/foo/DEFAULT.ASP RewriteRule (.*) http://example.com/foo$1 [R=301,L]
I added those lines to the .htaccess, but they do not work.
The second way I thought of is to use
Zend_Router_Route_Static
as follows:$router = $frontController->getRouter(); $route = new Zend_Controller_Router_Route_Static('foo/DEFAULT.ASP', array('controller' => 'foo', 'action' => 'index')); $router->addRoute('foo', $route);
This redirects to the correct page, but I have no idea how to set a 301 header as well, plus it's quite inelegant having those lines of code in my
bootstrap.php
Can anyone offer any advice on how to deal with this situation? I would like to know all or any of:
- How to get the rewrite rule to work
- How to do a '301' with
Zend_Controller_Router_Route
if possible. - Is there another way that I'm missing?
- Which is the better way and why?
- Why isn't google figuring this out? It has been nearly half a year.