Forum Moderators: phranque

Message Too Old, No Replies

RewriteCond and RewriteMap not playing well together

mod_rewrite.c and multiple redirects

         

bwdesign

3:53 am on Aug 12, 2005 (gmt 0)



Greetings all,

I've got the following rewrite rules that my cms ( [drupal.org ]) uses:


RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

The site has been in development but is now going to assume a URL of an existing site. We have to redirect all of their files (around 300) and I'm trying to figure out how to redirect in the .htaccess file.

Is there a way to do it with RewriteMap and a separate txt file?

Many thanks for your help,
Brett

jdMorgan

4:21 am on Aug 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RewriteMap is only available in httpd.conf, not in .htaccess.

You might be able to use this method in either httpd.conf or .htaccess: If the old files have any uniquely-identifying characteristics such as directory names, that can be used to advantage in reducing the number of required RewriteRules. For example, instead of redirecting each of 50 files in the directory "/dir" individually, you could simply redirect all files in that directory to a new directory-path:


RewriteRule ^dir/(.*)$ http://example.com/new_path/$1 [R=301,L]

That's a simple example; You could also extract the filename, modify it according to a fixed plan, and use the result in the new path:

RewriteRule ^dir/([^.])\.html$ http://example.com/new_path/new-$1.php [R=301,L]

or even:

RewriteRule ^dir/([^.])\.html$ http://example.com/script.php?oldname=$1 [R=301,L]

and let the script access a database to look up the new URL and do a 301 redirect.

Look for commonalities in the file path at the directory level, subdirectory level, and procieeding down to the individual file. You may have to use individual redirects if the original site was disorganized, but if you get the backlinks updated, then you won't need to leave the redirects (or at least, all of the redirects) in place forever.

Jim