简体   繁体   中英

.htaccess 301 Redirect with HTTPS

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?

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM