{"id":214,"date":"2011-06-27T07:52:00","date_gmt":"2011-06-27T07:52:00","guid":{"rendered":"http:\/\/pheonixsolutions.com\/?p=214"},"modified":"2026-04-16T22:35:10","modified_gmt":"2026-04-16T17:05:10","slug":"htaccess-redirection-2","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/htaccess-redirection-2\/","title":{"rendered":"How to redirect a website using .htaccess"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Website redirection is a common practice used to forward users from one URL to another. It is widely used during domain changes, website restructuring, or when moving from HTTP to HTTPS. In Apache-based web servers, redirection can be efficiently handled using the <strong>.htaccess<\/strong> file. This file allows administrators to control redirects without modifying the main server configuration, making it a simple and powerful solution for managing website traffic flow.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\"><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before setting up a website redirect using <code>.htaccess<\/code>, ensure the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You have access to your website\u2019s <strong>hosting control panel (cPanel or similar)<\/strong><\/li>\n\n\n\n<li>You have access to the <strong>root directory of your website (public_html)<\/strong><\/li>\n\n\n\n<li>The server is running <strong>Apache web server<\/strong> (supports <code>.htaccess<\/code>)<\/li>\n\n\n\n<li>Backup of the existing <code>.htaccess<\/code> file (recommended before making changes)<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">IMPLEMENTATION<\/h2>\n\n\n<div dir=\"ltr\" style=\"text-align: left;\"><br \/>\n<p><em>Redirect website http:\/\/mydomain.com to http:\/\/www.mynewdomain.com<\/em><br \/><strong>RewriteEngine on<br \/>RewriteCond %{HTTP_HOST} ^mydomain\\.com$<br \/>RewriteRule ^(.*)$ http:\/\/www.mynewdomain.com [R=301,L]<\/strong><\/p>\n<p><em>Redirect website mydomain.com with and without www requests to http:\/\/www.mynewdomain.com<\/em><br \/><strong>RewriteEngine on<br \/>RewriteCond %{HTTP_HOST} ^www\\.mydomain\\.com$ [OR]<br \/>RewriteCond %{HTTP_HOST} ^mydomain\\.com$<br \/>RewriteRule ^(.*)$ http:\/\/www.mynewdomain.com [R=301,L]<\/strong><\/p>\n<p><em>Redirect requests from http:\/\/mydomain.com to http:\/\/mydomain.com\/subdirectory i.e. redirecting requests from main domain to a sub-directory.<\/em><br \/><strong>RewriteEngine on<br \/>RewriteCond %{HTTP_HOST} ^www\\.mydomain\\.com$ [OR]<br \/>RewriteCond %{HTTP_HOST} ^mydomain\\.com$<br \/>RewriteRule ^(.*)$ http:\/\/www.mydomain.com\/subdirectory\/ [R=301,L]<\/strong><\/p>\n<p><em>Redirect all http (80) requests of a domain to https (443) i.e. redirecting requests from non-secure port to a secure port.<\/em><br \/><strong>RewriteEngine On<br \/>RewriteCond %{SERVER_PORT} !443<br \/>RewriteRule ^(.*)$ https:\/\/mydomain.com\/$1 [R,L]\u00c2\u00a0<br \/><br \/><br \/><\/strong><\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>Using <code data-start=\"1920\" data-end=\"1931\">.htaccess<\/code> for website redirection is a simple and effective method to manage traffic flow, improve SEO, and maintain user experience during domain or URL changes. Properly configured redirects ensure that visitors and search engines are automatically directed to the correct pages without errors or broken links. Always test your redirects after implementation to confirm they are working as expected.<\/p>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Introduction Website redirection is a common practice used to forward users from one URL to another. It is widely used [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1024],"tags":[],"class_list":["post-214","post","type-post","status-publish","format-standard","hentry","category-security","psol-cat-security"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-3s","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/214","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=214"}],"version-history":[{"count":2,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/214\/revisions"}],"predecessor-version":[{"id":9973,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/214\/revisions\/9973"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=214"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}