These steps explain how to set up redirects in a sites .htaccess file. This will allow the entire site to redirect to a separate domain, including subpages or file URLs. Access to cPanel is needed to complete the process below, which involves using the File Manager utility.
Related Articles
Set 301 Redirect in .htaccess File
- Log into cPanel
- Navigate to File Manager, located in the Files section
- Navigate to the Document Root for the domain
- Edit the .htaccess file, or create one
- Enter one of the following redirect codes into the
.htaccess
NOTE: The .htaccess file is a hidden (dot) file. Make sure to follow the process on showing hidden files if the file does not appear.Here is the code for redirecting to other domains homepage only, not to include subfolders and file links in the rewrite URL:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.net [L,R=301,NC]Here is the code for redirecting to other domain including subfolders and file links in the rewrite URL:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.net/$1 [L,R=301,NC]REPLACE: In the examples above replace example.com with the actual domain name that you intend to redirect to.
TIP: The difference here is the addition of $1 at the end of the URL. this is a regexp backreference that matches the regexp pattern ^(.*)$ at the start of this line. Anything the user typed into the URL is added to the redirect.
EXAMPLE: domain.com/somefile now becomes domain.net/somefile - Click Save
NOTE: If the server the domain resides on uses server side caching and cPanel includes Cache Manager utility be sure to purge the server side cache after making the .htaccess file edit.
Comments
0 comments
Article is closed for comments.