Support » How-To and Troubleshooting » Adding a 301 to WordPress .htaccess

Adding a 301 to WordPress .htaccess

  • Hi,

    I need to add in a 301 redirect to the standard WordPress .htaccess file as I moved my site from http://www.olddomain.com to http://www.newdomain.com.

    This is my current .htaccess file located in /news/

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /news/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /news/index.php [L]

    # END WordPress

    I’ve tried many things but none of them work, any ideas?

Viewing 7 replies - 1 through 7 (of 7 total)
  • I’ve looked all over this site and this question has been asked many times but never answered.

    I found it easier to use a plugin called Redirection.

    After the # END WordPress line you can simply do the following:

    Options +FollowSymlinks
    RewriteEngine on
    rewritecond %{http_host} ^domain.com [nc]
    rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

    Replace domain.com with your website. This ensures that all requests sent to the old website should be redirected to the new domain.

    P.S. this code should go in the htaccess of the old website and not the new one.



    Forum Moderator

    After the # END WordPress line

    No. Always add additional rules BEFORE the WordPress block

    Good point esmi. My bad there.

    Thank you for your feedback.

    The only issue with that solution is that I’ve pointed my new domain to the old domains location.

    In the root directory I have a .htaccess file with this:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^(www\.newdomain\.com)?$
    RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

    This works great.

    It’s just the WordPress URLs that aren’t getting redirected because they go via the sub folder /news/ which is where the WordPress .htaccess file resides to rewrite the nice URLs.

    You can write further URL rewrite rules to redirect old posts to the new posts, but if you do not have much posts, I would recommend you to use the “Permanent Redirect” rule in the htaccess file and make a rule for each URL.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Adding a 301 to WordPress .htaccess’ is closed to new replies.