Search Our Database
How to Create Site Redirect Using “.htaccess”
There are several ways to do a page redirection, one of the effective way to redirect a page or a website is by using .htaccess file.
.htaccess file can be found in the “public_html” folder. If the .htaccess file is still not created yet, you can simply create the file in your public_html folder.
Extra notes: Make sure that the ownership of the .htaccess file is set to the username.
Steps to redirect using .htaccess:-
- SSH to the server, or if you are doing it from the control panel, simply just go to the “file manager” from the control panel.
- Open the .htaccess file from the following path (this is directadmin path example, other control panel might have slight different path for the public_html) :-
-
/home/<user>/domains/<domain-name>/public_html/.htaccess
-
- To redirect website to other website, paste the script in the .htaccess file:-
-
RewriteEngine on RewriteCond %{HTTP_HOST} ^original-website-before-redirect.com.my [NC] RewriteRule ^(.*)$ http://www.new-website-to-be-redirected.com.my/$1 [L,R=301,NC]
-
- To redirect website to subdirectory, paste the script in the .htaccess file :-
-
RewriteEngine on RewriteCond %{HTTP_HOST} example\.com [NC] RewriteCond %{REQUEST_URI} ^/$ RewriteRule ^(.*)$ /subdirectory-name/$1 [L]
-
- To redirect website from http to https, paste the script in the .htaccess file :-
-
RewriteEngine on RewriteCond %{SERVER_PORT} ^80$ RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
-