I have spreadsheet which has column of 404 error link and its respective 301 redirects. for e.g)
404 error page 301 redirect
http://www.abc.com/1.php http://www.abc/com/2.php
.............. ............
The spreadsheet has around 1000+ links.
Is there any way in apache config or htaccess where can I handle bulk 301 redirects?
The best way for a Bulk setting is the RewriteMap directive in mod-rewrite. Note that this will not work in a .htaccess file. You'll need to edit it in a real apache configuration file (and the good news is that will be really faster than a .htaccess dynamic configuration).
Check the
txt:
keyword first.May be something like that:
When you'll get it working well transform the 302 in 301, and convert the txt file to an faster hashmap with the
dbm:
keyword (and ahttxt2dbm
command, but that's explained in the linked doc).include_once this file in 404.php - make sure 404.php is configured to be called when there is 404 :
Table structure:
surl = Source Url
durl = Destination Url
RewriteMap is indeed the way to go as stated by regilero. However, I couldn't understand how his code is supposed to work neither could I get it to work. One problem is that it assumes that there are no further rewrites (missing [L]) This does work:
In the apache config (does NOT work in .htaccess):
In .htaccess (also works in apache config):
In redirects.txt (Note: Slashes are NOT optional)
I'm not sure switching to dbm is worth the extra hassle. As stated on http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritemap , the lookup is cached in memory anyway.