I am using a wildcard redirect to redirect my old domain to a new domain. It works great but misses a few URLs (they don't get redirected to the destination and return status 200)
Can you please help me understand what's wrong with this? Maybe I am doing the wildcard redirect incorrectly or it's a server issue. My old domain is old.example
and my new domain is new.example
.
Example URL which isn't getting redirected: old.example/example-url
Here's my .htaccess
file:
# 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]
</IfModule>
# END WordPress
#Options +FollowSymLinks
# Redirect everything
RewriteRule ^(.*)$ /$1 [R=301,L]
I am using a wildcard redirect to redirect my old domain to a new domain. It works great but misses a few URLs (they don't get redirected to the destination and return status 200)
Can you please help me understand what's wrong with this? Maybe I am doing the wildcard redirect incorrectly or it's a server issue. My old domain is old.example
and my new domain is new.example
.
Example URL which isn't getting redirected: old.example/example-url
Here's my .htaccess
file:
# 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]
</IfModule>
# END WordPress
#Options +FollowSymLinks
# Redirect everything
RewriteRule ^(.*)$ https://new.example/$1 [R=301,L]
Share
Improve this question
edited Apr 24, 2020 at 18:35
Naser Mohd Baig
asked Apr 24, 2020 at 17:44
Naser Mohd BaigNaser Mohd Baig
256 bronze badges
2
- Is you new domain on a different server? – MrWhite Commented Apr 24, 2020 at 17:52
- No @MrWhite, it's on the same server. Will that cause any issue? – Naser Mohd Baig Commented Apr 24, 2020 at 18:01
1 Answer
Reset to default 1You've put the redirect directive in the wrong place. It needs to go before the WordPress front-controller, otherwise, the redirect will simply get ignored for anything other than URLs that map directly to the filesystem.
Since these domains are also on the same server (same hosting account I assume) then you will need to check for the requested hostname, otherwise, you'll get a redirect loop.
For example:
# Redirect everything from old to new domain
RewriteCond %{HTTP_HOST} ^old\.example [NC]
RewriteRule (.*) https://new.example/$1 [R=301,L]
# BEGIN WordPress
# :
The regex ^(.*)$
can be simplified to (.*)
since regex is greedy by default.