Link Search Menu Expand Document

.htaccess file

This file is a configuration file that controls how a webserver responds to various requests. It is supported by several webservers, including the popular Apache webserver used by most commercial web hosting providers.

The file operates at the level of a directory, allowing them to override global configuration settings of .htaccess directives higher in the directory tree.

Force https:// on CPanel

To force your website address from default http:// to https:// use the following:

RewriteEngine On 
RewriteCond %{HTTPS} !on 
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$ 
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$ 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


Redirect 301

Redirect 301 is a pointing one URL to another permanently. Here are some different use of redirect 301

Redirecting single URL

This is simply redirecting e.g. to or evendifferent website address

Redirect 301 /folder

Redirect the main folder but leave subfolders as they are

This is to redirect the main landing page of the old page to the new one but keeping the rest of the section/recursive path the same. E.g redicecting to other URL but keeping: the same.

RewriteCond %{REQUEST_URI} ^/folder/?$
RewriteRule (.*) /newfolder [R=301,L]

Redirect the whole folder including subfolders to one landing page

This is used to redirect the whole area of the website to one destination.

RewriteRule ^folder/(.*)$ [R=301,NC,L]
Redirect 301 /folder 

This will redirect and subfolders e.g* to

With this redirection, any folder under */folder/second-level wont be able to be redirected to a specific url because the RewiretRule will takeover the redirection behaviour.

For a subdomain, simply add the following to the .htaccess in this subdomain. This will redirect the subdomain and all folder under it go to the /new-landing-page

Redirect the whole folder including subfolders to one landing page, but cherry pick some to specific folder (RedirectMatch)

Redirecting the whole folder to one other destination but still able to choose some page under the folder to go somewhere else. E.g /folder/* is redirected to /new-folder but /folder/subfolder/ that is under /folder/* to go to other page.

RedirectMatch 301 ^/folder/second-level/(.*)$
RedirectMatch 301 ^/folder/(.*)$