You can use .htaccess to automatically redirect a visitor to another location, for example when you have a new website, or if your site is still under construction.
In this guide, you will find a description of some of the most commonly used functions and instructions on how to implement them on your web space at one.com using our File Manager.
Tip: If you want to redirect your whole website to another domain or IP-address, we recommend using DNS instead. Check out our guide on how to manage your DNS settings.
- Step 1 - Open your File Manager
- Step 2 - Find and edit the .htaccess file
- Step 3 - Make the necessary changes
- Step 4 - Click Save
- Step 5 - That's it!
Step 1 - Open your File Manager
Go to Files & Security > File Manager in your Control Panel.
You can also access your File Manager via the direct link: https://filemanager.one.com
Note: Before making any changes, it's wise to create a backup. You can do this by downloading the file to your local computer or by copying it within the File Manager.
Step 2 - Find and edit the .htaccess file
Locate the .htaccess file in your website's root directory. If you don't have one yet, follow the steps on how to create a new .htaccess file first. Click Edit in the pane to the right.
Step 3 - Make the necessary changes
Note: Be careful with syntax, as errors in this file can cause your site to malfunction.
Click on one of the frequently used redirects to view detailed implementation instructions.
-
301 redirect (permanent redirect)
You can permanently redirect your visitors to another location, a process known as a 301 redirect.
The number 301 stands for the http status code. Adding the number 301, tells search engines that the address has permanently moved to another location, consequently moving your page ranking as well..
Redirect 301 /oldpage.html https://www.one-example.com/newpage.html
Replace /oldpage.html with the current page name and https://www.one-example.com/newpage.html with the new location. Make sure all text is on one line.
-
Redirect to www.yourdomain.com
You might want to do this to improve your search engine ranking. Search engines recognize www.yourdomain.com and yourdomain.com as two different pages, it is better if only one page is used.
#Rewrite to domain with www RewriteEngine On RewriteCond %{HTTP_HOST} !^(.+\.)([a-zA-Z0-9-]+\.([a-z]{2,4})|co\.uk|me\.uk|org\.uk|priv\.no)$ RewriteCond %{HTTP_HOST} ([a-zA-Z0-9-]+\.([a-z]{2,4})|co\.uk|me\.uk|org\.uk|priv\.no)$ RewriteRule ^(.*)$ https://www.%1/$1 [L,QSA,R=301]
-
Redirect to yourdomain.com
Similar to redirecting to www, but the other way around. It serves the same purpose.
#Rewrite to domain without www RewriteEngine On RewriteCond %{HTTP_HOST} ^www\.(.*) RewriteRule ^(.*) https://%1/$1 [QSA,L,R=301]
-
Rewrite everything to HTTPS
If you have activated SSL on your web space you can rewrite all traffic to https://. That way you can make sure that your visitors only use a secure connection. If you only want to redirect to https:// in certain folders on your site, you can add the .htaccess file to that specific folder.
#Rewrite everything to https RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Step 4 - Click Save
Click the Save button to save your changes.
Step 5 - That's it!
Check your website to make sure everything is working properly. If you encounter any errors, you can restore from the backup copy.
Related articles: