Gerald Ferreira Gerald Ferreira - 3 months ago 16
PHP Question

htaccess wordpress https rewrite rule

I am hoping that you can help me with the htaccess rewrite rule below.

# BEGIN WordPress

# WPhtc: Begin Custom htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress


I have recently changed my wordpress site from http to https... The problem is that old url's redirect to the domain name instead of the https version of that page

eg

if I access the following page
https://domain.com/test/testing/
it works 100%, now if I change the
https
part to
http
then the page redirects to
https://domain.com
instead of to
https://domain.com/test/testing/
how do I fix it so that if you go to the old version page
http://domain.com/test/testing/
(the not https version) that it redirects to
https://domain.com/test/testing/
instead of just the domain name
https://domain.com

Answer

You have to find a workaround for %{REQUEST_FILENAME} since this only represents the file that is accessed. But you obviously want to access the SSL vHost. So you might hardcode the https into your .htaccess.

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

This might help you alot. (found the code above there)