Help with htaccess https redirect

Hi Pullo,
Can you please help me with .htaccess file?
I have SSL certificate installed
my website opens in both condition

  1. https: // domain.com
  2. https:// www. domain. com

I want website to open only with https:// www. domain. com - this structure

Please help me with .htacceess content

You need to redirect non-www to www in addition to redirecting http to https

RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule .? http://www.domain.com%{REQUEST_URI} [R=301]

should do the trick.

I have already tried this code.
This code solves the issue of redirection to https:// www. domain. com but all my posts and pages show error 401

Perhaps if you show us what you already have in your .htaccess then…

1 Like

Here’s my .htaccess file

#RewriteEngine On 
#RewriteCond %{SERVER_PORT} 80 443
#RewriteRule ^(.*)$ https://www. domain .com/$1 [R,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php56” package as the default “PHP” programming language.
<IfModule mime_module>
  AddType application/x-httpd-ea-php56 .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

<Files 403.shtml>
order allow,deny
allow from all
</Files>

Hello! Help me out pls!
I have already shared my .htaccess file

A general observation, rather than an answer to your question:

<IfModule mod_rewrite.c>

You should only use IfModule once, for testing. Once you have established that the module is enabled, remove the IfModule rule. Otherwise you are continually wasting system resources needlessly checking for the existence of the module when you already know it is there.

2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.