2

アプリケーションをApacheからNginXに移動しようとしていますが、.htaccessファイルを書き直す必要があることがわかりました。よく調べましたが、最終的に助けを求める必要があります。

以下はApacheの.htaccessファイルです。/html、/css、/images、/phpへのリクエストを除いて、すべてのリクエストをindex.phpにリダイレクトしようとしています。

事前にご協力いただきありがとうございます。明細書

RewriteEngine on 
RewriteRule ^html [L,NC]
RewriteRule ^css [L,NC]
RewriteRule ^images [L,NC]
RewriteRule ^php [L,NC]
RewriteRule ^.*$ index.php [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !directory/(.*)$
RewriteCond %{REQUEST_URI} !(.*)$
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

これまでのところ、以下があり、html、css、画像、および php ファイルの要求はうまく機能しています。

しかし、私が www.domain.com/blah/blah/blah/ をリクエストすると 404 が返されます。私が本当に必要としているのは、URL を www.domain.com/blah/blah/blah/ としてリーミングすることですが、 index.php ファイル

location ~ directory/(.*)$ {
}

location ~ (.*)$ {
}

location /html {
rewrite ^/html / break;
}

location /css {
rewrite ^/css / break;
}

location /images {
rewrite ^/images / break;
}

location /php {
rewrite ^/php / break;
}

location / {
rewrite ^(.*)$ /index.php break;
if (!-e $request_filename){
rewrite ^(.*)$ http://www.domain.com/$1 redirect;
}
}
4

1 に答える 1

0

特定のフォルダー内のコンテンツへの要求をフィルタリングするには、次の行に沿って何かを試してください。

RewriteEngine On
# if not requesting content in one of the specified folders
RewriteCond %{REQUEST_FILENAME} !^(html|css|images|php)/ [NC]
# redirect visitor to the index page
RewriteRule ^(.*)$ index.php [L,QSA]

書き換え条件の前の感嘆符 ( ! ) は否定を意味するため、要求されたファイル名が html または css または .... で始まらない場合は、書き換え規則を適用します。

于 2012-05-07T11:01:31.853 に答える