: Always redirecting to https without www I have a website and have recently installed an SSL certificate. I want all links to the site to always redirect to the secure site without www, as
I have a website and have recently installed an SSL certificate. I want all links to the site to always redirect to the secure site without www, as I have made the SSL applicable to non-www.
Furthermore, I have WHMCS in the backend and want to redirect the example.com/whmcs
page to example.com/client-portal as I have a third party plugin that links with whmcs.
What should I insert in my .htaccess file and in what folders should I insert the file? Can I specify everything from root and if this is the case, how do I force WHMCS to be happy with this?
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www.)?(.*)$ [NC]
RewriteRule (.*) %1%{REQUEST_URI} [L,R=301]
Edit
The good news is that I have solved the first part of the problem. All URLs now redirect to the non-www https website. The code that solved this issue was supplied by @John Conde - thanks John!
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www.)?(.*)$ [NC]
RewriteRule (.*) %1%{REQUEST_URI} [L,R=301]
My next goal is to have example.com/whmcs redirect to example.com/client-portal.
...but without redirecting example.com/whmcs/admin to example.com/client-portal/admin. In other words, /whmcs/admin should not redirect.
I have tried the following solution but without success. I'll appreciate it if you guys can help.
RewriteCond !^example.com/whmcs/admin
RewriteCond ^example.com/whmcs$
RewriteRule example.com/client-portal [R=301,L]
My intention was that this causes /whmcs to redirect but not for /whmcs/admin to redirect.
More posts by @Kaufman445
3 Comments
Sorted by latest first Latest Oldest Best
I realized that it does not yet redirect the non-www site under the HTTPS protocol. It does however work fine under the HTTP protocol. Here is an extract of my complete .htaccess file:
RewriteOptions inherit
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*.php)$ [L]
RewriteRule . index.php [L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^(?:www.)?(.*)$ [NC]
RewriteRule (.*) %1%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www.)?(.*)$ [NC]
RewriteRule (.*) %1%{REQUEST_URI} [L,R=301]
#RewriteCond !^example.com/clients/bestuur #RewriteCond ^example.com/clients$ #RewriteRule example.com/client-portal [R=301,L]
You could also take the approach of multiple rewrite rules. Replace example.com with your actual domain name.
RewriteEngine On
RewriteCond %{HTTPS} off
# HTTPS is off!
# Redirect to the secure canonical URL
RewriteRule (.*) example.com/ [L,R=301]
RewriteCond %{HTTP_HOST} !^example.com$ [NC]
# Host name is not correct!
# (maybe it has a www?)
# Redirect to the secure canonical URL
RewriteRule (.*) example.com/ [L,R=301]
As for the succeedonline.co.za/whmcs redirect, you can use a single simple rewrite rule for that:
RewriteRule ^whmcs$ example.com/client-portal [L,R=301]
The ^ means "starts with" and the $ means "ends with", so that redirect will only get triggered when the URL is exactly succeedonline.co.za/whmcs and not when it is succeedonline.co.za/whmcs/admin.
Not sure if this would encompass your goal completely, but this would turn http www mode into https non-www mode:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ example.com/ [R=301,L]
Then to redirect the whmcs to a new url, you can probably use a simple 301:
Redirect 301 /whmcs /client-portal
These would both go into the root of your app, or optionally at the place where an A record is picked up.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.