2014-01-10 93 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