Redirect from old domain to new domain not work

I try to Redirect from old domain to new domain, By below code, but not work, Where is error.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.mydomain.com$
RewriteRule ^/?$ "http://mydomain.com/" [R=301,L]
</IfModule>

# END WordPress

Related posts

Leave a Reply

1 comment

  1. You need to place redirect rule before WP catch-all rule otherwise you will only get index.php after redirect on new domain:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC]
    RewriteRule ^ http://newdomain.com%{REQUEST_URI} [NE,R=301,L]
    
    RewriteRule ^index.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>