2017-03-15 6 views
0

最近ApacheをNginxに使ったウェブサイトを移動しました。 URLから.PHPを維持しながらhttp://example.com/login.phpを指すようにnginx - phpファイル用のURLを書き換えよう

http://example.com/login 

は、どのように私はこのようになりますURLを得ることができますか?

私の現在の構成:

server { 
    listen 80; 
    listen [::]:80; 

    root /var/www/example.com/html/; 
    index index.php index.html; 

    server_name example.com www.example.com; 

    location/{ 
      try_files $uri $uri/ =404; 
    } 

    # deny accessing php files for the /assets directory 
    location ~ ^/assets/.*\.php$ { 
      deny all; 
    } 

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
    # 
    location ~ \.php$ { 
      include snippets/fastcgi-php.conf; 

      # With php7.0-cgi alone: 
      # fastcgi_pass 127.0.0.1:9000; 
      # With php7.0-fpm: 
      fastcgi_pass unix:/run/php/php7.0-fpm.sock; 
    } 
} 

答えて

0

私は通常、このようなものを使用し、それがSEOの証明です。多くのクライアントサイトでテストされ、魅力的な作品です。あなたの/etc/nginx/conf.d/domain.tld.confファイルで

はこれを含める:

server { 
    index index.html index.php; 
    location/{ 
    if ($request_uri ~ ^/(.*)\.html$) { return 302 /$1; } 
    try_files $uri $uri/ $uri.html $uri.php?$args; 
    } 
    location ~ \.php$ { 
    if ($request_uri ~ ^/([^?]*)\.php($|\?)) { return 302 /$1?$args; } 
    try_files $uri =404; 
    # add fastcgi_pass line here, depending if you use socket or port 
    } 
} 

Source i used a while a go

+0

あなたの答えをいただき、ありがとうございます。私の現在の設定では...どのように動作するのですか?私はしようとしましたが、nginxサーバーは再起動しませんでした。 – Ciprian