2016-08-09 1 views
1

私はApache2で.htaccessを使用していますが、うまくいきます。Nginxでrewriteを使うには?

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([A-Za-z0-9_]+)$ profile.php?username=$1 

、今私はnginxの書き換えを使用し、サイトで利用可能で、私はこの設定

server { 
listen 80; 
server_name domain.com; 
root /home/domain; 
index index.html index.htm index.php; 
location/{ 
    rewrite "^([A-Za-z0-9_]+)$" profile.php?username=$1 last; 
} 
location ~ \.php$ { 
    fastcgi_split_path_info ^(.+\.php)(/.+)$; 
    fastcgi_pass unix:/var/run/php5-fpm.sock; 
    fastcgi_index index.php; 
    include fastcgi_params; 
} 
location ~ /\.ht { 
    deny all; 
} 
} 

を作るが、それは動作しません、それは404が見つかりません示して、あなたは私にエラーを助けることができますか?ありがとう。

答えて

0

書き換えの翻訳に問題があります。このコードでこの更新されたリライト翻訳を確認してください。

server { 
listen 80; 
server_name domain.com; 
root /home/domain; 
index index.html index.htm index.php; 
location/{ 
if (!-e $request_filename){ 
rewrite ^/([A-Za-z0-9_]+)$ /profile.php?username=$1; 
} 
} 
location ~ \.php$ { 
    fastcgi_split_path_info ^(.+\.php)(/.+)$; 
    fastcgi_pass unix:/var/run/php5-fpm.sock; 
    fastcgi_index index.php; 
    include fastcgi_params; 
} 
location ~ /\.ht { 
    deny all; 
} 
} 
+0

{ '、.htaccessファイルでは、'するRewriteCond%{REQUEST_FILENAME}を使用(!-e $ REQUEST_FILENAME)場合は、ここで '使うべき理由を説明することができ、ありがとうございました!-f'と'するRewriteCond% {REQUEST_FILENAME}!-d'。 – yeleko

関連する問題