Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

I've moved my blog over to the new domain now and used the .htaccess file to redirect all requests from the old domain to this one.

Here's what I've used:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !newdomain.com$ [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301]


What this does is:
1. Turns on the URL rewriting engine in Apache
2. Sets the base URL to the root of the domain
3. Checks if the requested URL is not the new domain using case insensitive matching via the [NC] flag
4. Specifies the new URL to be the same as the requested URL, with the domain name changed to the new domain.

The L flag specifies this is the last rule to evaluate if a match is found and R=301 specifies that a HTTP 301 redirect is sent, which flags that the requested page has permanently moved to the new domain location.



-i

A quick disclaimer...

Although I put in a great effort into researching all the topics I cover, mistakes can happen. Use of any information from my blog posts should be at own risk and I do not hold any liability towards any information misuse or damages caused by following any of my posts.

All content and opinions expressed on this Blog are my own and do not represent the opinions of my employer (Oracle). Use of any information contained in this blog post/article is subject to this disclaimer.
Hi! You can search my blog here ⤵
NOTE: (2022) This Blog is no longer maintained and I will not be answering any emails or comments.

I am now focusing on Atari Gamer.