1

My website redirects everything from http to https but 1 of the redirects is a none cacheable 302 redirect according to a few seo checkers i use.

How can i get the following code to be a 301 redirect instead of a 302?

    Options +FollowSymLinks
    RewriteEngine on

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^lincoln-printing-services\.co\.uk$ [NC]
RewriteCond %{HTTP_HOST} !^www\.lincoln-printing-services\.co\.uk$ [NC]
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
RewriteRule ^index\.php$ - [L]
2

Try appending [R=301] to your RewriteRule entries. If you have existing parameters (like [L]), comma-separate them: [R=301,L].

1

The following changed the 302 to a 301 between http://www and https://www

RewriteEngine On
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.