Hi. I've been trying to redirect all URLs from an old domain to a new one, except for two specific pages (/contact-form and /about). Here is the code block I have added at the top of .htaccess file just before #Beging Wordpress:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)olddomain\.com$ [NC]
RewriteRule ^(contact-form|about)($|/) - [L]
# Exclude specific file extensions from redirection
RewriteCond %{THE_REQUEST} !/contact-form/?\s [NC]
RewriteCond %{REQUEST_URI} !\.(css|js|png|jpg|gif||webp|ico)$ [NC]
RewriteCond %{THE_REQUEST} !/about/?\s [NC]
RewriteCond %{REQUEST_URI} !\.(css|js|png|jpg|gif||webp|ico)$ [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]
Although the redirections take place, I encounter a 404 server error specifically on the excluded pages (olddomain.com/contact-form and /about) when visiting them:
404 Not Found
The resource requested could not be found on this server!
However, when I test the same .htaccess code block on localhost (Xampp, Apache server), it works well. Any help would be appreciated.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)olddomain\.com$ [NC]
RewriteRule ^(contact-form|about)($|/) - [L]
# Exclude specific file extensions from redirection
RewriteCond %{THE_REQUEST} !/contact-form/?\s [NC]
RewriteCond %{REQUEST_URI} !\.(css|js|png|jpg|gif||webp|ico)$ [NC]
RewriteCond %{THE_REQUEST} !/about/?\s [NC]
RewriteCond %{REQUEST_URI} !\.(css|js|png|jpg|gif||webp|ico)$ [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]
Although the redirections take place, I encounter a 404 server error specifically on the excluded pages (olddomain.com/contact-form and /about) when visiting them:
404 Not Found
The resource requested could not be found on this server!
However, when I test the same .htaccess code block on localhost (Xampp, Apache server), it works well. Any help would be appreciated.