0

.htaccess 書き換えルールを nginx 構成に変換する際に助けが必要です。ルールは、メトロ縮小 URL 短縮スクリプトからのものです。

RewriteEngine On 
#RewriteBase /

RewriteRule ^developer.html$            developer.php [QSA,L]
RewriteRule ^multishrink.html$          multishrink.php [QSA,L]
RewriteRule ^stats.html$                public-stats.php [QSA,L]
RewriteRule ^feed.rss                   feed.php [QSA,L]
RewriteRule ^([^/]+)\.qrcode$           qrcode.php?id=$1 [QSA,L]
RewriteRule ^api.php$                   API/simple.php [QSA,L]
RewriteRule ^API/write/(get|post)$      API/write.php?method=$1 [QSA,L]
RewriteRule ^API/read/(get|post)$       API/read.php?method=$1 [QSA,L]
RewriteRule ^([^/]+)/stats$             stats.php?id=$1 [QSA,L]
RewriteRule ^([^/]+)/unlock$            unlock.php?id=$1 [QSA,L]

# If path is not a directory or file then apply RewriteRule
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d        
RewriteRule ^([0-9a-zA-Z-]{1,60})$      go.php?id=$1 [QSA,L]
4

2 に答える 2

0

試す:

location = /developer.html { 
   rewrite ^(.*)$ /developer.php break; 
} 

location = /multishrink.html { 
   rewrite ^(.*)$ /multishrink.php break; 
} 

location = /stats.html { 
   rewrite ^(.*)$ /public-stats.php break; 
} 

location /feed { 
   rewrite ^/feed.rss /feed.php break; 
} 

location / { 
   rewrite ^/([^/]+)\.qrcode$ /qrcode.php?id=$1 break; 
   rewrite ^/([^/]+)/stats$ /stats.php?id=$1 break; 
   rewrite ^/([^/]+)/unlock$ /unlock.php?id=$1 break; 
   if (!-e $request_filename){ 
      rewrite "^/([0-9a-zA-Z-]{1,60})$" /go.php?id=$1 break; 
   } 
} 

location = /api.php { 
   rewrite ^(.*)$ /API/simple.php break; 
} 

location /API { 
   rewrite ^/API/write/(get|post)$ /API/write.php?method=$1 break; 
   rewrite ^/API/read/(get|post)$ /API/read.php?method=$1 break; 
}
于 2012-09-13T17:12:28.257 に答える
0

次のようにする必要があります。

location = /developer.html { rewrite ^ developer.php last; }
location = /multishrink.html { rewrite ^ multishrink.php last; }
location = /stats.html { rewrite ^ stats.php last; }

location ~ ^feed.rss { rewrite ^ feed.php last; }
location ~ ^([^/]+)\.qrcode$ { rewrite ^([^/]+)\.qrcode$ qrcode.php?id=$1 last; }

location = /api.php { rewrite ^ API/simple.php; }
location ~ ^API/(write|read)/(get|post)$ { 
  rewrite ^API/(write|read)/(get|post)$ API/$1.php?method=$2 last;     
} 

location ~ ^([^/]+)/stats$ { rewrite ^([^/]+)/stats$ stats.php?id=$id last;}

location ~ ^([^/]+)/unlock$ {
  set $id $1;
  rewrite ^ unlock.php?id=$id last;  
}

location ~ "^([0-9a-zA-Z-]{1,60})$" {
  try_files $uri $uri/ go.php?id=$1;
}

注:最初に保存することで場所の正規表現からキャプチャを再利用することができます(ロック解除場所のように)、または正規表現を繰り返すことができます(保存の必要性は、書き換えディレクティブがキャプチャ変数をリセットするという事実から生じます) )。お好みのスタイルを使用してください。

注: nginx はデフォルトでクエリ引数を追加するため、Apache の qsa フラグが本質的にデフォルトです

 If a replacement string includes the new request arguments, the previous request 
 arguments are appended after them. If this is undesired, putting a question mark
 at the end of a replacement string avoids having them appended
于 2012-09-13T17:40:19.170 に答える