Redirect Old Domain To New Domain With .htaccess

Redirect Old Domain To New Domain With .htaccess

Assuming that your web server runs on Apache, which is pretty much the norm for any shared hosting service out in the wild, here’s how you can redirect your old domain name to a new one, while keeping your SEO juices.

Using any file editor available, edit the .htaccess file at the root folder, which is usually public_html .Add the following to the very start of the file, regardless of whether your .htaccess is empty or not

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTP_HOST} ^olddomainhere.com$ [OR]
  RewriteCond %{HTTP_HOST} ^www.olddomainhere.com$
  RewriteRule (.*)$ http://www.newdomainhere.com/$1 [R=301,L]
</IfModule>

The above will redirect the homepage, and any other pages. For example, the following

1. http://olddomainhere.com/
2. http://www.olddomainhere.com/
3. http://olddomainhere.com/redirect-old-domain-to-new-domain-with-htaccess

Redirects to the following respectively

1. http://www.newdomainhere.com/
2. http://www.newdomainhere.com/
3. http://www.newdomainhere.com/redirect-old-domain-to-new-domain-with-htaccess

Should you require any assistance, let me know in the comments below and I will try my best to help.

Enjoyed the content ? Share it with your friends !

Redirect http to https with htaccess

Redirect http to https with htaccess

Here’s how you can redirect http to https by manually editing your .htaccess file. This will allow you to avoid the need for plugins or the like, while also giving you more control of what you want redirected.

Redirect all HTTP traffic to HTTPS 

# BEGIN HTTPS REDIRECT
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
# END HTTPS REDIRECT

Redirect a subfolder or directory only

# BEGIN HTTPS REDIRECT
# edit 'www.example.com' and the subdirectory (the two 'secure')
<IfModule mod_rewrite.c>
RewriteEngine On 
RewriteCond %{SERVER_PORT} !^443$ 
RewriteCond %{REQUEST_URI} secure 
RewriteRule ^(.*)$ https://www.example.com/secure/$1 [R,L]
</IfModule>
# END HTTPS REDIRECT

 

This should work fine on both apache, and litespeed, since both supports the mod_rewrite module

Enjoyed the content ? Share it with your friends !