{"id":13806,"date":"2019-04-06T09:22:37","date_gmt":"2019-04-06T09:22:37","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=13806"},"modified":"2019-04-06T09:22:37","modified_gmt":"2019-04-06T09:22:37","slug":"redirect-a-website-url-from-one-server-to-different-server-in-apache","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/06\/redirect-a-website-url-from-one-server-to-different-server-in-apache\/","title":{"rendered":"Redirect a Website URL from One Server to Different Server in Apache"},"content":{"rendered":"<p>As promised in our previous two articles (<a href=\"https:\/\/www.tecmint.com\/redirection-with-mod_rewrite-in-apache\/\" target=\"_blank\" rel=\"noopener\">Perform Internal Redirection with mod_rewrite<\/a>\u00a0and\u00a0<a href=\"https:\/\/www.tecmint.com\/mod_rewrite-redirect-requests-based-on-browser\/\" target=\"_blank\" rel=\"noopener\">Show Custom Content Based on Browser<\/a>), in this post we will explain how to perform a redirection to a resource that has been moved from one server to a different server in Apache using\u00a0<strong>mod_rewrite<\/strong>\u00a0module.<\/p>\n<p>Suppose you are redesigning your company\u2019s Intranet site. You have decided to store the content and styling (<strong>HTML files<\/strong>,\u00a0<strong>JavaScript<\/strong>, and\u00a0<strong>CSS<\/strong>) on one server and the documentation on another \u2013 perhaps a more robust one.<\/p>\n<p><b>Suggested Read:<\/b>\u00a0<a href=\"https:\/\/www.tecmint.com\/apache-performance-tuning\/\" target=\"_blank\" rel=\"noopener\">5 Tips to Boost the Performance of Your Apache Web Server<\/a><\/p>\n<p>However, you want this change to be transparent to your users so that they are still able to access the docs at the usual URL.<\/p>\n<p>In the following example, a file named\u00a0<code>assets.pdf<\/code>\u00a0has been moved from\u00a0<strong>\/var\/www\/html<\/strong>\u00a0in\u00a0<strong>192.168.0.100<\/strong>(hostname:\u00a0<strong>web<\/strong>) to the same location in\u00a0<strong>192.168.0.101<\/strong>\u00a0(hostname:\u00a0<strong>web2<\/strong>).<\/p>\n<p>In order for users to access this file when they browse to\u00a0<code>192.168.0.100\/assets.pdf<\/code>, open Apache\u2019s configuration file on\u00a0<strong>192.168.0.100<\/strong>\u00a0and add the following rewrite rule (or you can also add the following rule to your\u00a0<a href=\"https:\/\/www.tecmint.com\/tag\/htaccess\/\" target=\"_blank\" rel=\"noopener\">.htaccess file<\/a>):<\/p>\n<pre>RewriteRule \"^(\/assets\\.pdf$)\" \"http:\/\/192.168.0.101$1\"  [R,L]\r\n<\/pre>\n<p>where\u00a0<code>$1<\/code>\u00a0is a placeholder for anything that matches the regular expression inside parentheses.<\/p>\n<p>Now save changes, don\u2019t forget to restart Apache, and let\u2019s see what happens when we attempt to access\u00a0<strong>assets.pdf<\/strong>\u00a0by browsing to\u00a0<strong>192.168.0.100\/assets.pdf<\/strong>:<\/p>\n<p><b>Suggested Read:<\/b>\u00a0<a href=\"https:\/\/www.tecmint.com\/apache-htaccess-tricks\/\" target=\"_blank\" rel=\"noopener\">25 Useful \u2018.htaccess\u2019 Tricks for Websites<\/a><\/p>\n<p>In the above below we can see that the request that was made for\u00a0<strong>assets.pdf<\/strong>\u00a0on\u00a0<strong>192.168.0.100<\/strong>\u00a0was actually handled by\u00a0<strong>192.168.0.101<\/strong>.<\/p>\n<pre># tail -n 1 \/var\/log\/apache2\/access.log\r\n<\/pre>\n<div id=\"attachment_23612\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/11\/Check-Apache-Logs.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-23612\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/11\/Check-Apache-Logs.png\" alt=\"Check Apache Logs\" width=\"585\" height=\"84\" aria-describedby=\"caption-attachment-23612\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-23612\" class=\"wp-caption-text\">Check Apache Logs<\/p>\n<\/div>\n<p>In this article we have discussed how to perform a redirection to a resource that has been moved to a different server. To wrap up, I\u2019d strongly suggest you take a look at the\u00a0<a href=\"http:\/\/mod-rewrite-cheatsheet.com\/\" target=\"_blank\" rel=\"nofollow noopener\">mod_rewrite<\/a>\u00a0guide and\u00a0<a href=\"https:\/\/httpd.apache.org\/docs\/2.4\/rewrite\/remapping.html\" target=\"_blank\" rel=\"nofollow noopener\">Apache redirect guide<\/a>\u00a0for future reference.<\/p>\n<p>As always, feel free to use the comment form below if you have any concerns about this article. We look forward to hearing from you!<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/redirect-website-url-from-one-server-to-different-server\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As promised in our previous two articles (Perform Internal Redirection with mod_rewrite\u00a0and\u00a0Show Custom Content Based on Browser), in this post we will explain how to perform a redirection to a resource that has been moved from one server to a different server in Apache using\u00a0mod_rewrite\u00a0module. Suppose you are redesigning your company\u2019s Intranet site. You have &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/04\/06\/redirect-a-website-url-from-one-server-to-different-server-in-apache\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Redirect a Website URL from One Server to Different Server in Apache&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-13806","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13806","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=13806"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13806\/revisions"}],"predecessor-version":[{"id":13807,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/13806\/revisions\/13807"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=13806"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=13806"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=13806"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}