301 Redirect vs Rewrite
301 Redirect
in an .htaccess
does not require the mod_rewrite library. It's a much simpler way to redirect, but it doesn't have the flexibility and power you get using the Rewrite rules. If you have a 1-1 mapping with explicit urls you can use the Redirect:
Redirect 301 /path/file.html http://new.site.com/newpath.php
If you're trying to do wild card matching of a number of similar patterns using regular expressions you'll need to use Rewrite.
RewriteRule ^(.*).html$ http://new.site.com/$1.php [R=301,NC,L]
Here's a pretty good overview of the 2 methods: http://www.ksl-consulting.co.uk/301-redirect-examples.html
Renee
Updated on May 09, 2020Comments
-
Renee about 4 years
I have a site that was hosted by someone else all the web pages were .html files. I am now hosting the site and have changed it to a wordpress site. The domain has not changed but obviously all the pages have. What is the best way to redirect all the .html pages to the main url?
-
Boris_yo about 10 yearsWhat if I want to redirect WWW and non-WWW version? Can I do this without RewriteRule or mod_rewrite library?
-
Ray about 10 years@Boris_yo no, you need rewrite conditions if you're trying to catch the protocol http vs. https
-
Boris_yo about 10 yearsNot really a protocol but WWW and non-WWW
-
Ray about 10 years@Boris_yo you can't catch domian / host names either with Redirect, only a RewriteRule with a RewriteCondition:
RewriteCond %{HTTP_HOST} ^foo.com[nc]
RewriteRule ^(.*)$ http://www.foo.com/$1 [r=301,nc]