{"id":1216,"date":"2014-04-02T10:30:50","date_gmt":"2014-04-02T10:30:50","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=1216"},"modified":"2025-03-30T16:45:11","modified_gmt":"2025-03-30T15:45:11","slug":"redirect-to-new-domain","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/htaccess\/redirect-to-new-domain","title":{"rendered":"Redirect to new domain"},"content":{"rendered":"\n<p><span style=\"color: #ff0000;\"><strong><em>Note &#8211;&nbsp; browsers cache redirects &#8211; if you change a redirect and then try again your browser may not be hitting the old domain when you return!!!&nbsp; Try using temporary redirect code 307&nbsp;when you debug in place of 301 permanent redirect???<\/em><\/strong><\/span><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Redirect codes<\/h4>\n\n\n\n<p>301 &#8211; permanent redirect<\/p>\n\n\n\n<p>307&nbsp;&#8211; Temporary redirect<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Redirect from old domain to new domain<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteEngine on\nRewriteBase \/\nRewriteRule (.*) http:\/\/www.newdomain.com\/$1 &#91;R=301,L]<\/code><\/pre>\n\n\n\n<p>or to redirect to the root directory always<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteEngine on\nRewriteBase \/\nRewriteRule (.*) http:\/\/www.newdomain.com\/ &#91;R=301,L]<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Redirect a single page<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>Redirect 301 \"\/old-page.html\" \"https:\/\/www.new.com\/new-page.html\"<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Redirect a directory and all sub directories from an old domain to new domain<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Removing the original directory from the path (with .htaccess in the root)<\/h5>\n\n\n\n<p>https:\/\/my-old-domain\/my-old-directory\/my-filename<br>redirects to:<br>https:\/\/my-new-domain.com\/my-new-directory\/my-filename<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#Redirect My site\nRewriteEngine on\nRewriteRule ^my-old-directory(\/.*)?$ https:\/\/my-new-domain.com\/my-new-directory\/$1 &#91;R=301,L]<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Keeping the original directory in the path (with .htaccess in the root)<\/h5>\n\n\n\n<p>https:\/\/my-old-domain\/my-old-directory\/my-filename<br>redirects to:<br>https:\/\/my-new-domain.com\/my-new-directory\/my-old-directory\/my-filename<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteEngine on\nRewriteBase \/my-old-directory\/\nRewriteRule (.*) https:\/\/my-new-domain.com\/my-new-directory\/$1 &#91;R=301,L]<\/code><\/pre>\n\n\n\n<p>or to redirect to the root directory always<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteEngine on\nRewriteBase \/mydirectory\/\nRewriteRule (.*) http:\/\/www.newdomain.com\/mydirectory\/ &#91;R=301,L]<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Not sure the above is correct, the following worked redirecting a subdirectory from a domain to a new domain<\/h5>\n\n\n\n<p>Redirect anything in this&nbsp;directory or any sub directory off it: http:\/\/myoldomain.com\/api\/v100\/<\/p>\n\n\n\n<p>To this new domain and new sub directory: http:\/\/mynewdomain.com\/mynewsubdirectory\/api\/v100\/<\/p>\n\n\n\n<p>This in the root &#8220;http:\/\/myoldomain.com\/&#8221;.htaccess&nbsp;file worked:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteEngine on\nRewriteBase \/api\/v100\/\nRewriteRule (.*) http:\/\/mydomain.com\/mynewsubdirectory\/$1 &#91;R=301,L]<\/code><\/pre>\n\n\n\n<p>But placing it in the .htaccess file in the directory &#8220;http:\/\/myoldomain.com\/api\/v100\/&#8221; instead, this was needed:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>RewriteEngine on\nRewriteBase \/api\/v100\/\nRewriteRule (.*) http:\/\/mydomain.com\/mynewsubdirectory\/api\/v100\/$1 &#91;R=301,L]<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Note &#8211;&nbsp; browsers cache redirects &#8211; if you change a redirect and then try again your browser may not be hitting the old domain when you return!!!&nbsp; Try using temporary redirect code 307&nbsp;when you debug in place of 301 permanent redirect??? Redirect codes 301 &#8211; permanent redirect 307&nbsp;&#8211; Temporary redirect Redirect from old domain to [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[75],"tags":[],"class_list":["post-1216","post","type-post","status-publish","format-standard","hentry","category-htaccess"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1216","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=1216"}],"version-history":[{"count":13,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1216\/revisions"}],"predecessor-version":[{"id":4800,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1216\/revisions\/4800"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=1216"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=1216"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=1216"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}