Mercurial > hg > nginx-site
view xml/ja/docs/http/converting_rewrite_rules.xml @ 1974:95bcadfde4fc
Removed duplicate "transparent" parameter.
author | Yaroslav Zhuravlev <yar@nginx.com> |
---|---|
date | Fri, 21 Apr 2017 21:20:26 +0300 |
parents | 130fad6dc1b4 |
children |
line wrap: on
line source
<!DOCTYPE article SYSTEM "../../../../dtd/article.dtd"> <article name="rewrite ルールのコンバート" link="/ja/docs/http/converting_rewrite_rules.html" lang="ja"> <section name="メインサイトへのリダイレクト"> <para> 共有のホスティングで Apache の .htaccess ファイル<i>のみ</i>で<i>すべて</i>を設定してきたのなら、次のようにルールをコンバートします: <programlisting> RewriteCond %{HTTP_HOST} example.org RewriteRule (.*) http://www.example.org$1 </programlisting> 上記は下記のようになります: <programlisting> server { listen 80; server_name www.example.org example.org; if ($http_host = example.org) { rewrite (.*) http://www.example.org$1; } ... } </programlisting> </para> <para> これは間違っていて面倒で非効率的な方法です。正しい方法は <literal>example.org</literal> 用に別のサーバを定義します: <programlisting> server { listen 80; server_name example.org; rewrite ^ http://www.example.org$request_uri?; } server { listen 80; server_name www.example.org; ... } </programlisting> </para> </section> <section> <para> 別の例として、<literal>example.com</literal> 以外と <literal>www.example.com</literal> 以外のすべて、という後方ロジックの代わりの例です: <programlisting> RewriteCond %{HTTP_HOST} !example.com RewriteCond %{HTTP_HOST} !www.example.com RewriteRule (.*) http://www.example.com$1 </programlisting> この場合、単に <literal>example.com</literal>、<literal>www.example.com</literal>、そしてそれ以外を定義します: <programlisting> server { listen 80; server_name example.org www.example.org; ... } server { listen 80 default_server; server_name _; rewrite ^ http://example.org$request_uri?; } </programlisting> </para> </section> <section id="converting_mongrel_rules" name="Mongrel ルールのコンバート"> <para> 典型的な Mongrel のルール: <programlisting> DocumentRoot /var/www/myapp.com/current/public RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f RewriteCond %{SCRIPT_FILENAME} !maintenance.html RewriteRule ^.*$ %{DOCUMENT_ROOT}/system/maintenance.html [L] RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^(.*)$ $1 [QSA,L] RewriteCond %{REQUEST_FILENAME}/index.html -f RewriteRule ^(.*)$ $1/index.html [QSA,L] RewriteCond %{REQUEST_FILENAME}.html -f RewriteRule ^(.*)$ $1/index.html [QSA,L] RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L] </programlisting> 上記は次のようにコンバートされます <programlisting> location / { root /var/www/myapp.com/current/public; try_files /system/maintenance.html $uri $uri/index.html $uri.html @mongrel; } location @mongrel { proxy_pass http://mongrel; } </programlisting> </para> </section> </article>