Path: blob/main/xml/ja/docs/http/converting_rewrite_rules.xml
1 views
<!DOCTYPE article SYSTEM "../../../../dtd/article.dtd">12<article name="rewrite ルールのコンバート"3link="/ja/docs/http/converting_rewrite_rules.html"4lang="ja">56<section name="メインサイトへのリダイレクト">78<para>9共有のホスティングで Apache の .htaccess ファイル<i>のみ</i>で<i>すべて</i>を設定してきたのなら、次のようにルールをコンバートします:1011<programlisting>12RewriteCond %{HTTP_HOST} example.org13RewriteRule (.*) http://www.example.org$114</programlisting>1516上記は下記のようになります:1718<programlisting>19server {20listen 80;21server_name www.example.org example.org;22if ($http_host = example.org) {23rewrite (.*) http://www.example.org$1;24}25...26}27</programlisting>28</para>2930<para>31これは間違っていて面倒で非効率的な方法です。正しい方法は <literal>example.org</literal> 用に別のサーバを定義します:3233<programlisting>34server {35listen 80;36server_name example.org;37rewrite ^ http://www.example.org$request_uri?;38}3940server {41listen 80;42server_name www.example.org;43...44}45</programlisting>46</para>4748</section>495051<section>5253<para>54別の例として、<literal>example.com</literal> 以外と <literal>www.example.com</literal> 以外のすべて、という後方ロジックの代わりの例です:5556<programlisting>57RewriteCond %{HTTP_HOST} !example.com58RewriteCond %{HTTP_HOST} !www.example.com59RewriteRule (.*) http://www.example.com$160</programlisting>6162この場合、単に <literal>example.com</literal>、<literal>www.example.com</literal>、そしてそれ以外を定義します:636465<programlisting>66server {67listen 80;68server_name example.org www.example.org;69...70}7172server {73listen 80 default_server;74server_name _;75rewrite ^ http://example.org$request_uri?;76}77</programlisting>78</para>7980</section>818283<section id="converting_mongrel_rules"84name="Mongrel ルールのコンバート">8586<para>87典型的な Mongrel のルール:8889<programlisting>90DocumentRoot /var/www/myapp.com/current/public9192RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f93RewriteCond %{SCRIPT_FILENAME} !maintenance.html94RewriteRule ^.*$ %{DOCUMENT_ROOT}/system/maintenance.html [L]9596RewriteCond %{REQUEST_FILENAME} -f97RewriteRule ^(.*)$ $1 [QSA,L]9899RewriteCond %{REQUEST_FILENAME}/index.html -f100RewriteRule ^(.*)$ $1/index.html [QSA,L]101102RewriteCond %{REQUEST_FILENAME}.html -f103RewriteRule ^(.*)$ $1/index.html [QSA,L]104105RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]106</programlisting>107108上記は次のようにコンバートされます109110<programlisting>111location / {112root /var/www/myapp.com/current/public;113114try_files /system/maintenance.html115$uri $uri/index.html $uri.html116@mongrel;117}118119location @mongrel {120proxy_pass http://mongrel;121}122</programlisting>123</para>124125</section>126127</article>128129130