From f52e15fbd1f70370d5141d380fdbe8b445fec0f6 Mon Sep 17 00:00:00 2001 From: geekpi Date: Thu, 29 Dec 2016 15:54:54 +0800 Subject: [PATCH] translated --- ...ne Server to Different Server in Apache.md | 65 ------------------- ...ne Server to Different Server in Apache.md | 63 ++++++++++++++++++ 2 files changed, 63 insertions(+), 65 deletions(-) delete mode 100644 sources/tech/20161203 Redirect a Website URL from One Server to Different Server in Apache.md create mode 100644 translated/tech/20161203 Redirect a Website URL from One Server to Different Server in Apache.md diff --git a/sources/tech/20161203 Redirect a Website URL from One Server to Different Server in Apache.md b/sources/tech/20161203 Redirect a Website URL from One Server to Different Server in Apache.md deleted file mode 100644 index 10e7faec92..0000000000 --- a/sources/tech/20161203 Redirect a Website URL from One Server to Different Server in Apache.md +++ /dev/null @@ -1,65 +0,0 @@ -translating---geekpi - -Redirect a Website URL from One Server to Different Server in Apache -============================================================ - -As promised in our previous two articles ([Perform Internal Redirection with mod_rewrite][1] and [Show Custom Content Based on Browser][2]), 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 mod_rewrite module. - -Suppose you are redesigning your company’s Intranet site. You have decided to store the content and styling (HTML files, JavaScript, and CSS) on one server and the documentation on another – perhaps a more robust one. - -**Suggested Read:** [5 Tips to Boost the Performance of Your Apache Web Server][3] - -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. - -In the following example, a file named `assets.pdf` has been moved from /var/www/html in 192.168.0.100(hostname: web) to the same location in 192.168.0.101 (hostname: web2). - -In order for users to access this file when they browse to `192.168.0.100/assets.pdf`, open Apache’s configuration file on 192.168.0.100 and add the following rewrite rule (or you can also add the following rule to your [.htaccess file][4]): - -``` -RewriteRule "^(/assets\.pdf$)" "http://192.168.0.101$1" [R,L] -``` - -where `$1` is a placeholder for anything that matches the regular expression inside parentheses. - -Now save changes, don’t forget to restart Apache, and let’s see what happens when we attempt to access assets.pdf by browsing to 192.168.0.100/assets.pdf: - -**Suggested Read:** [25 Useful ‘.htaccess’ Tricks for Websites][5] - -In the above below we can see that the request that was made for assets.pdf on 192.168.0.100 was actually handled by 192.168.0.101. - -``` -# tail -n 1 /var/log/apache2/access.log -``` -[ - ![Check Apache Logs](http://www.tecmint.com/wp-content/uploads/2016/11/Check-Apache-Logs.png) -][6] - -Check Apache Logs - -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’d strongly suggest you take a look at the [mod_rewrite][7] guide and [Apache redirect guide][8] for future reference. - -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! - --------------------------------------------------------------------------------- - -作者简介:Gabriel Cánepa is a GNU/Linux sysadmin and web developer from Villa Mercedes, San Luis, Argentina. He works for a worldwide leading consumer product company and takes great pleasure in using FOSS tools to increase productivity in all areas of his daily work. - ------------ - -via: http://www.tecmint.com/redirect-website-url-from-one-server-to-different-server/ - -作者:[Gabriel Cánepa][a] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]:http://www.tecmint.com/author/gacanepa/ -[1]:http://www.tecmint.com/redirection-with-mod_rewrite-in-apache/ -[2]:http://www.tecmint.com/mod_rewrite-redirect-requests-based-on-browser/ -[3]:http://www.tecmint.com/apache-performance-tuning/ -[4]:http://www.tecmint.com/tag/htaccess/ -[5]:http://www.tecmint.com/apache-htaccess-tricks/ -[6]:http://www.tecmint.com/wp-content/uploads/2016/11/Check-Apache-Logs.png -[7]:http://mod-rewrite-cheatsheet.com/ -[8]:https://httpd.apache.org/docs/2.4/rewrite/remapping.html diff --git a/translated/tech/20161203 Redirect a Website URL from One Server to Different Server in Apache.md b/translated/tech/20161203 Redirect a Website URL from One Server to Different Server in Apache.md new file mode 100644 index 0000000000..be65f0eb6e --- /dev/null +++ b/translated/tech/20161203 Redirect a Website URL from One Server to Different Server in Apache.md @@ -0,0 +1,63 @@ +在Apache中重定向URL从一台服务器到另外一台服务器上 +============================================================ + +如我们前面两篇文章([使用mod_rewrite执行内部重定向][1]和[基于浏览器显示自定义内容][2])中所承诺的,在本文中,我们将解释如何在Apache中使用mod_rewrite模块将已移动的资源重定向到不同服务器上。 + +假设你正在重新设计公司的网站。你已决定将内容和样式(HTML文件,JavaScript和CSS)存储在一个服务器上,将文档存储在另一个服务器上 - 这样可能会更稳健。 + +**建议阅读:** [5个提高Apache Web服务器性能的提示][3] + +但是,你希望这个更改对用户透明,以便他们仍然能够通过常用网址访问文档。 + +在下面的例子中,名为“assets.pdf”的文件已从192.168.0.100(主机名:web)中的/var/www /html移动到192.168.0.101(主机名:web2)中的相同位置。 + +为了让用户在浏览到“192.168.0.100/assets.pdf”时访问此文件,请打开192.168.0.100上的Apache配置文件并添加以下重写规则(或者也可以将以下规则添加到[.htaccess文件][4])中: + +``` +RewriteRule "^(/assets\.pdf$)" "http://192.168.0.101$1" [R,L] +``` + +其中`$1`是与括号中的正则表达式匹配的任何内容的占位符。 + +现在保存更改,不要忘记重新启动Apache,让我们看看当我们打开192.168.0.100/assets.pdf,尝试访问assets.pdf时会发生什么: + +**建议阅读:** [25有用的网站的'.htaccess'技巧] [5] + +在下面我们就可以看到,为192.168.0.100上的assets.pdf所做的请求实际上是由192.168.0.101处理的。 + +``` +# tail -n 1 /var/log/apache2/access.log +``` +[ + ![Check Apache Logs](http://www.tecmint.com/wp-content/uploads/2016/11/Check-Apache-Logs.png) +][6] + +检查Apache日志 + +在本文中,我们讨论了如何对已移动到其他服务器的资源进行重定向。 总而言之,我强烈建议你看看[mod_rewrite][7]指南和[Apache重定向指南][8],以供将来参考。 + +一如既往那样,如果您对本文有任何疑虑,请随时使用下面的评论栏回复。 我们期待你的回音! + +-------------------------------------------------------------------------------- + +作者简介:Gabriel Cánepa是来自阿根廷圣路易斯Villa Mercedes的GNU/Linux系统管理员和Web开发人员。 他在一家全球领先的消费品公司工作,非常高兴使用FOSS工具来提高他日常工作领域的生产力。 + +----------- + +via: http://www.tecmint.com/redirect-website-url-from-one-server-to-different-server/ + +作者:[Gabriel Cánepa][a] +译者:[geekpi](https://github.com/geekpi) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]:http://www.tecmint.com/author/gacanepa/ +[1]:http://www.tecmint.com/redirection-with-mod_rewrite-in-apache/ +[2]:http://www.tecmint.com/mod_rewrite-redirect-requests-based-on-browser/ +[3]:http://www.tecmint.com/apache-performance-tuning/ +[4]:http://www.tecmint.com/tag/htaccess/ +[5]:http://www.tecmint.com/apache-htaccess-tricks/ +[6]:http://www.tecmint.com/wp-content/uploads/2016/11/Check-Apache-Logs.png +[7]:http://mod-rewrite-cheatsheet.com/ +[8]:https://httpd.apache.org/docs/2.4/rewrite/remapping.html