2014-01-10 130 views
1

長話短說,我有一個osCommerce安裝,使用osCommerce的「搜索引擎友好鏈接」在Apache服務器上運行多年,以便鏈接看起來像product_info.php/products_id/26而不是product_info.php?products_id = 26。Nginx重寫幫助請求

那麼,現在我已經轉移到一個PHP5的Nginx服務器和搜索引擎友好鏈接現在不適合我。但我有所有跨使用「友好」的鏈接指向我店的網頁鏈接,所以我必須想出一個辦法來重定向任何URL,它是這樣的:

product_info.php/products_id/26 

這個

product_info.php?products_id=26 

index.php/cPath/19 

index.php?cPath=19 

product_info.php/cPath/19/products_id/207 

product_info.php?cPath=19&products_id=207 

任何人都好有Nginx的重寫規則,或者誰知道如何使自從內置SEO網址Nginx的工作嗎? osCommerce網址不需要任何htaccess重寫規則;它看起來像是所有使用PHP代碼的照顧。

nginx.conf:

user nginx; 
worker_processes 4; 

error_log /var/log/nginx/error.log warn; 
pid  /var/run/nginx.pid; 


events { 
    worker_connections 1024; 
} 


http { 
    include  /etc/nginx/mime.types; 
    default_type application/octet-stream; 

    log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 
         '$status $body_bytes_sent "$http_referer" ' 
         '"$http_user_agent" "$http_x_forwarded_for"'; 

    access_log /var/log/nginx/access.log main; 

    sendfile  on; 
    #tcp_nopush  on; 

    keepalive_timeout 65; 

    #gzip on; 

    server_names_hash_bucket_size 10240; 

    include /etc/nginx/conf.d/*.conf; 
    include /etc/nginx/sites-available/*.vhost; 

} 

site.com.vhost:

server { 
     listen *:80; 
     server_name site.com www.site.com; 
     root /var/www/clients/client23/web5/web; 
     index index.php index.html index.htm; 

     #location ~ \.shtml$ { 
     # ssi on; 
     #} 

     error_log /var/log/ispconfig/httpd/site.com/error.log; 
     access_log /var/log/ispconfig/httpd/site.com/access.log combined; 

     location ~ /\. { 
      deny all; 
      access_log off; 
      log_not_found off; 
     } 

     location = /favicon.ico { 
      log_not_found off; 
      access_log off; 
     } 

     location = /robots.txt { 
      allow all; 
      log_not_found off; 
      access_log off; 
     } 

     location /stats { 
      index index.html index.php; 
      auth_basic "Members Only"; 
      auth_basic_user_file /var/www/clients/client23/web5/web/stats/.htpasswd_stats; 
     } 

     location ^~ /awstats-icon { 
      alias /usr/share/awstats/icon; 
     } 

     location ~ \.php$ { 
      try_files /5lbe4fd76b7f89.htm @php; 
     } 

     location @php { 
      try_files $uri =404; 
      include /etc/nginx/fastcgi_params; 
      fastcgi_pass unix:/var/lib/php5-fpm/web2.sock; 
      fastcgi_index index.php; 
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
      fastcgi_intercept_errors on; 
     } 



    # Static Contents 
    location ~* ^.+.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf)$ { 
    access_log off; 
    log_not_found off;     
    expires 1y;     
    } 
    # CSS and JS 
    location ~* ^.+.(css|js)$ { 
    access_log off; 
    log_not_found off;     
    } 

    server_tokens off; 
    error_page 400 /400.php; 
    error_page 401 /401.php; 
    error_page 403 /403.php; 
    error_page 404 /404.php; 
    error_page 405 /405.php; 
    error_page 500 /500.php; 
    error_page 502 /502.php; 
    error_page 503 /503.php; 
    recursive_error_pages off; 
    fastcgi_intercept_errors on; 

    # Inaccessible locations 
location ~ ^/includes/.*\.php$ { return 404; } 
location ~ ^/administrator/includes/.*\.php$ { return 404; } 
location ^~ /administrator/backups { return 404; } 
location ^~ /download { return 404; } 
location ^~ /cgi-bin { return 404; } 
location ^~ /mail { return 404; } 
location ^~ /pub { return 404; } 
location ^~ /sql { return 404; } 
location ^~ /temp { return 404; } 

location ~ /\. { deny all; access_log off; log_not_found off; } 
location ~ \.(tpl|log|sql)$ {deny all; access_log off; log_not_found off; } 

location/{ 

    #if (!-e $request_filename) { rewrite ^(.*)$ /index.php; } 

     fastcgi_pass unix:/var/lib/php5-fpm/web2.sock; 
    fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    include fastcgi_params; 


    rewrite ^/(.*)-(.*).html$ /index.php?cPath=$2&$query_string; 
    rewrite ^/(.*)-m-([0-9]+).html$ /index.php?manufacturers_id=$2&$query_string; 
    rewrite ^/(.*)-pi-([0-9]+).html$ /popup_image.php?pID=$2&$query_string; 
    rewrite ^/(.*)-t-([0-9]+).html$ /articles.php?tPath=$2&$query_string; 
    rewrite ^/(.*)-a-([0-9]+).html$ /article_info.php?articles_id=$2&$query_string; 
    rewrite ^/(.*)-pr-([0-9]+).html$ /product_reviews.php?products_id=$2&$query_string; 
    rewrite ^/(.*)-pri-([0-9]+).html$ /product_reviews_info.php?products_id=$2&$query_string; 
    rewrite ^/(.*)-i-([0-9]+).html$ /information.php?info_id=$2&$query_string; 
    } 

     location /administrator/ { 
       auth_basic "Members Only"; 
       auth_basic_user_file /var/www/clients/client23/web5/web/administrator/.htpasswd; 

       location ~ \.php$ { 
        try_files /wj70wjksdkj2jiejlsjdslj.htm @php; 
       } 
     } 

} 
+0

之前回答,請註明您目前nginx的配置,或者在至少它的主要部分。 –

+0

你好,穆罕默德!我添加了當前的nginx配置文件。 – user3157244

回答

0

這裏,我們去:

rewrite "^/product_info.php/products_id/(\d+)" /product_info.php?products_id=$1 permanent; 

rewrite "^/index.php/cPath/(\d+)" /index.php?cPath=$1 permanent; 

rewrite "^/product_info.php/cPath/(\d+)/products_id/(\d+)" /product_info.php?cPath=$1&products_id=$2 permanent; 
+0

即將301重定向,我假設要求是以Apache/Mod_Rewrite的方式透明地將SEO URL重寫爲oscommerce URL。 – edmondscommerce