Reputation: 421
I recently had a client site change a page name, for SEO purposes, and we needed to do a redirect on the old link to the new one, but for some reason its not working correctly.
The .htaccess looks like this:
AddHandler php5-script .php
RewriteEngine On # Turn on the rewriting engine
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Redirect 301 /oldpage1 /newpage1
Redirect 301 /oldpage2 /newpage2
But the page gets redirected to be:
http://examplesite.com:443/newpage1
I've even tried doing the 301's like this:
Redirect 301 /oldpage1 https://examplesite.com/newpage1
Both ways produce the same result. Any ideas?
Upvotes: 1
Views: 117
Reputation: 786091
You should not mix mod_rewrite
rules with mod_alias
ones and also you need to keep external redirect rules before internal rewrite ones.
Try this:
AddHandler php5-script .php
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
RewriteRule ^oldpage1/?$ /newpage1 [L,NC,R=301]
RewriteRule ^oldpage2/?$ /newpage2 [L,NC,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]
Upvotes: 1