How to add Redirect 301 rule in .htaccess file

In an Apache .htaccess file, you typically add the Redirect 301 rule in the section where you want to manage URL redirections. The Redirect directive is used to create simple URL redirections, and the 301 indicates that the redirection is permanent (HTTP status code 301).

# This is a comment
<IfModule mod_rewrite.c>
    RewriteEngine On
    # Rewrite rules go here
</IfModule>

# Redirect rules can be placed outside the mod_rewrite block
Redirect 301 /old-page.html http://www.example.com/new-page.html

In the example above, the Redirect 301 rule is placed outside the <IfModule mod_rewrite.c> block, which is used for enabling the mod_rewrite module. This is because the Redirect directive is not a part of the mod_rewrite module.

You can place the Redirect 301 rule at the end of your .htaccess file or within a specific section, depending on your requirements. Just remember that the rules are processed from top to bottom, so the order matters. If you have more complex redirection needs or want to use regular expressions, you might consider using mod_rewrite instead.

Leave a comment

Your email address will not be published. Required fields are marked *