• Hi all,

    Last week I changed the my website from http to https. It concerns the website .
    Despite the 301 redirect rule in the htaccess, all old (http) pages are redirected with a 302 redirect for some reason. I cannot find what this is and did not change any plugins at all. The only thing I created was an extra rule in the htaccess.

    Here an overview of my htaccess file.

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteCond %{SERVER_PORT} ^80$
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301]
    RewriteBase /
    RewriteRule ^index\.php$ – [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress

    # BEGIN GzipWpFastestCache
    <IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE image/svg+xml
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE text/javascript
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE application/x-font-ttf
    AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
    AddOutputFilterByType DEFLATE font/opentype font/ttf font/eot font/otf
    </IfModule>
    # END GzipWpFastestCache
    ## BROWSER CACHING ##
    ExpiresActive On
    ExpiresByType image/jpg “access 1 year”
    ExpiresByType image/jpeg “access 1 year”
    ExpiresByType image/gif “access 1 year”
    ExpiresByType image/png “access 1 year”
    ExpiresByType text/css “access 1 month”
    ExpiresByType application/pdf “access 1 month”
    ExpiresByType text/x-javascript “access 1 month”
    ExpiresByType application/x-shockwave-flash “access 1 month”
    ExpiresByType image/x-icon “access 1 year”
    ExpiresDefault “access 1 week”
    ## BROWSER CACHING ##

    However, currently I will only see 302 redirects when checking all the pages.
    How can I make sure that a 301 redirect will be in place instead of a 302 redirect?

    Regards!
    Marc

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hello, try changing your RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301] to end with [R=301,L] the L stands for [L]ast this means that this will be the last rule of the chain. Maybe some plugin or the server is adding extra rules somehow so as they are chained the 301 is followed by a 302 after your htaccess rule.

    Thread Starter mmarcvh

    (@mmarcvh)

    Thans Xenos,

    Thanks for your quick respoonse.
    Unfortunately the solution is not working.

    There must be another line overruling?

    Redirect log; [R=301,L]
    http://www.janjippe.nl/
    HTTP/1.1 302 Found
    Date: Fri, 01 Sep 2017 07:16:11 GMT
    Server: Apache/2
    Location: https://www.janjippe.nl/
    Cache-Control: max-age=604800
    Expires: Fri, 08 Sep 2017 07:16:11 GMT
    Content-Length: 208
    Content-Type: text/html; charset=iso-8859-1

    Possibly try using the Rewrite Rules Inspector plugin. It is tested up to version 4.8.

    Hello @mmarcvh,

    You can add below line in your <VirtualHost *:80> virtual host file to resolve this error.

    Redirect 301 / https://www.janjippe.nl/

    Please let me know if you need any more help on this.

    Thanks,
    Chetan

    Thread Starter mmarcvh

    (@mmarcvh)

    Hi Chetan, do you mean adding only the Redirect 301 rule like this?

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteCond %{SERVER_PORT} ^80$
    Redirect 301 / https://www.janjippe.nl/
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    RewriteBase /
    RewriteRule ^index\.php$ – [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    Or do I need to add the rule <VirtualHost *:80> as well?

    Thank you!

    Thread Starter mmarcvh

    (@mmarcvh)

    If I place only Redirect 301 (as shown in example) I will get an infinite loop of redirects for only homepage/ Other pages will be offline.

    Hello,

    I have the same problem here – 302 redirects are active by default when setting site up to https. I have tried to add some rules in htaccess, but it loops up to “too many redirects”.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘302 redirect instead of 301 after switch to https’ is closed to new replies.