Redirecting With .htaccess
Need to get your visitors from one spot to the next? Have one of yur pages changed locations? .htaccess redirection may be what you are looking for. There are many types of redirection in .htaccess, so I’ll make sure to explain each of them, and their uses!
A 301 redirect is for when you permanently move a page’s location. A 301 redirect not only redirects the visitor to the new page, but also informs search engines like Google that the page has moved. You will not be punished for using this, and Google will index the new page to show to your visitors.
Redirect 301 /old_page.html http://www.domain.com/new_page.html
A 302 redirect is for when you temporarily move a page’s location. A 302 redirect not only redirects the visitor to the new page, but also informs search engines like Google that the page has only moved for a short period of time, and will come back to it's original location soon.
Redirect 302 /old_page.html http://www.domain.com/new_page.html
Since it is technically a type of redirection, I will include it here. Error pages are shown to visitors when an error like “Not Found” (404) or “Forbidden” (403) is encountered on your website. To learn more, check out the article on error pages.
Redirection from one domain to another while keeping the file path
Changed domain names? Some of your visitors may have your old pages bookmarked, and you don’t want to just redirect them to your new homepage! .htaccess makes it simple to redirect visitors from one domain to another while keeping the rest of the URL path intact. For example, if I went to olddomain.com/contect.html, I would be redirected to newdomain.com/contact.html.
RedirectMatch 301 ^/(.*)$ http://domain.com/$1
Remember to replace domain.com with your real domain name, and “http” with “https” if your site uses SSL.
That's it! Super simple, but also super useful to know. It will definitely save you time, and it’s even SEO friendly (Always a plus)! See you next time.