301 redirect using .htaccess I wonder if the following 301 redirect is the best way for my situation. I used this post on SO to give me the following 301 redirect:

RewriteRule locations\.php$ compare-biomass.php [R=301]


What we've done is changed a filename from locations.php to compare-biomass.php.

The new URL should be:


  www.mydomain.com/compare-biomass.php?variable1=1&amp;variable2=2&amp;variable3=3.


The above SO post mentioned that the old query string gets appended to the new filename, which is exactly what I want. However, I found that I was being redirected so that SERVER["DOCUMENT_ROOT"] was being appended to the domain, so the URL was:


  www.mydomain.com/home/mydomain/public_html/compare-biomass.php?variable1=1&amp;variable2=2&amp;variable3=3


I worked out that I had to include the following in my .htaccess file

RewriteBase /


However, now that I've had a problem and this is the very first time I'm doing anything related to Apache, can you please tell me if the .htaccess file I'm using is optimal for me:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
RewriteBase /
RewriteRule locations\.php$ compare-biomass.php [R=301]
Since the RewriteBase directive applies to the entire .htaccess file, it should not be buried between two RewriteRules.

You don't need capturing parentheses for the RewriteCond.

Options +FollowSymLinks

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule .* http://www.example.com/$0 [R=301,L]

RewriteRule ^locations\.php$ compare-biomass.php [R=301]