views:

225

answers:

3

I'm wondering if multiple entries on htaccess will work for 301 redirects.

The problem I see is that old site files have 'html' extension and are named named differently so a simple global redirect won't work, it has to be one rule per file name.

This sites receives 1000 visits daily so need to be careful not to penalize search engine.

RewriteEngine On
RewriteBase /
RewriteRule ^file1\.html$ http://www.domain.com/file1.php [R=301,NC,L]
RewriteRule ^file2\.html$ http://www.domain.com/file2.php [R=301,NC,L]
RewriteRule ^file3\.html$ http://www.domain.com/file3.php [R=301,NC,L]
RewriteRule ^file4\.html$ http://www.domain.com/file4.php [R=301,NC,L]

A php header rewrite will not work as the old files are html type.

+1  A: 

Why not just...

RewriteRule ^file([0-9]+)\.html$ http://www.metaboforte.com/file$1.php [R=301,NC,L]

Or, if you want to rewrite everything on the old site...

RewriteRule ^(.*?)\.html$ http://www.metaboforte.com/$1.php [R=301,NC,L]
VoteyDisciple
Thanks for your post.
Codex73
+2  A: 

I suppose you could use some regex to reduce the number of different RewriteRules you are using, as those are all looking the same way.

In your case, using only this one might be OK :

RewriteRule ^(file1|file2|file3|file4)\.html$ http://www.metaboforte.com/$1.php [R=301,NC,L]

This way, you specify exactly what you want to rewrite ; but only have 1 RewriteRule.

Or, a bit more generic :

RewriteRule ^file([0-9]*)\.html$ http://www.metaboforte.com/file$1.php [R=301,NC,L]

Which allows you to define that you want to rewrite every fileXYZ.html, with XYZ a number. (As I used '*', no number at all would be taken into account by that rewrite rule ; if you want at least one number, you should use '+')

You could also do something even more generic -- not sure you want that, but something like this might do :

RewriteRule ^(.*?)\.html$ http://www.metaboforte.com/$1.php [R=301,NC,L]

Here, you are redirecting everything that end with .html

Pascal MARTIN
A: 

Maybe you can try the RewriteMap Directive

Ian Yang