magento - 如何为 Magento 的多语言 SEO URL 重写 Nginx

标签 magento url nginx seo

我正在使用 fastcgi 在 Nginx 上开发多语言 Magento。一切正常,除了我似乎无法像使用 Apache 那样获取 URL。

我想从 url 中删除 index.php。示例:

/es/index.php/category.html 到 /es/category.html

还有英文 /index.php/category.html 到 /类别.html

就这些。

附加信息:

我已尝试在管理中将“使用 Web 服务器重写”设置为。这只适用于英语,即默认,但随后我得到 404 西类牙语,除了在主页上!

如果我在管理中将“使用 Web 服务器重写”设置为,那么除了将 index.php 添加到 URL 之外一切正常。但是,如果我从 URL 中手动删除 index.php,页面仍会转到 404。

此外,在 Magento Administration 中,我有这样的基本 URL 设置:https://www.examplesite.com/es/和 {{secure_base_url}}../skin/等

我的根/es/中有一个文件夹,其中包含 index.php 的副本,如下所示:

/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';

/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';

Mage::run('es');

这是我的 Nginx 配置:

worker_processes  1;

error_log                           /mba/nginx/logs/error.log;
pid                                 /mba/nginx/logs/nginx.pid;

events {
    worker_connections              2048;
}
http {
    include                         mime.types;
    default_type                    application/octet-stream;
    server_names_hash_bucket_size   64;
    open_file_cache                 max=100 inactive=1m; 
    open_file_cache_valid           20s;
    open_file_cache_min_uses        1;
    open_file_cache_errors          on;
    fastcgi_buffers                 256 4k; 
    ignore_invalid_headers          on; 
    client_header_buffer_size       1k;
    client_body_buffer_size         64k;
    large_client_header_buffers     4 8k;
    client_body_timeout             60;
    client_header_timeout           60;
    keepalive_requests              100;    
    keepalive_timeout               300 300;
    keepalive_disable               msie6;
    send_timeout                    60; 
    max_ranges                      1;  
    reset_timedout_connection       on; 
    sendfile        on; 
    sendfile_max_chunk              512k;
    server_tokens                   off; 
    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                      /mba/nginx/logs/access.log  main;

    autoindex off;
    map $scheme $fastcgi_https { ## Detect when HTTPS is used
        default off;
        https on;
    }

    gzip                            on;
    gzip_static                     on;
    gzip_disable                    "MSIE [1-6]\.";
    gzip_vary                       on;
    gzip_comp_level                 2;
    gzip_min_length                 0;
    gzip_proxied                    any;
    gzip_types                      text/plain image/x-icon image/bmp text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    proxy_buffering on;
    #proxy_cache_path               /mba/nginx/proxy levels=1:2 keys_zone=one:15m inactive=7d max_size=1000m;
    proxy_buffer_size               4k;
    proxy_buffers                   100 16k;
    proxy_connect_timeout           60;
    proxy_send_timeout              60;
    proxy_read_timeout              60;
    #include                         /mba/nginx/conf.d/*.conf;

    ##
    # SSL Support
    ##
    map $scheme $fastcgi_https {
    default off;
        https on;
    }

server {
    listen                          80;
    #listen                         443 default ssl;
    expires                         max;
    add_header                      Cache-Control public;   
    #ssl_certificate                /openssl/ssl/www_mybelovedangels_com.crt;
    #ssl_certificate_key            /openssl/ssl/www_mybelovedangels_com.key;
    #access_log                     /mba.nginx.1/mba/nginx/logs/access_log;
    root                            /mba.nginx.1/mba/www;

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    expires                         +60d;
    log_not_found                   off;
    } 
location / {
    index index.html index.php;
    try_files $uri $uri/ @handler;
    expires +30d;
    deny    192.168.1.1;
    allow   192.168.1.0/24;
    allow   127.0.0.1;
    allow   2620:100:e000::8001;
    deny    all;
    }

    # Deny access to specific directories no one
    # in particular needs access to anyways.
    location /app/ { deny all; }
    location /includes/ { deny all; }
    location /lib/ { deny all; }
    location /media/downloadable/ { deny all; }
    location /pkginfo/ { deny all; }
    location /report/config.xml { deny all; }
    location /var/ { deny all; }

    # Allow only those who have a login name and password
    # to view the export folder. Refer to /etc/nginx/htpassword.
    location /var/export/ {
        auth_basic "Restricted";
        auth_basic_user_file htpasswd;
        autoindex on;
    }

    # Deny all attempts to access hidden files
    # such as .htaccess, .htpasswd, etc...
    location ~ /\. {
         deny all;
         access_log off;
         log_not_found off;
    }

    # This redirect is added so to use Magentos
    # common front handler when handling incoming URLs.
    location @handler {
        rewrite / /index.php;
    }

    # Forward paths such as /js/index.php/x.js
    # to their relevant handler.
    location ~ .php/ {
        rewrite ^(.*.php)/ $1 last;
    }

    # Handle the exectution of .php files.
    location ~ .php$ {
        if (!-e $request_filename) {
            rewrite / /index.php last;
        }
        expires off;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param HTTPS $fastcgi_https;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param MAGE_RUN_CODE en;
        fastcgi_param MAGE_RUN_TYPE store;
        include fastcgi_params;
    }
  }
}

我希望这不是太多信息,但可能需要它。我在网上到处找都找不到,而且我对如何执行此操作一无所知。

谢谢

最佳答案

为此域编辑您的 vhost 配置文件并添加以下内容:

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

然后确保 Magento 设置为从 url 中排除 index.php 这应该在您启用 Use Web Server Rewrites 时发生

关于magento - 如何为 Magento 的多语言 SEO URL 重写 Nginx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13896194/

相关文章:

sql - Postgresql 用户未连接到数据库(Nginx Django Gunicorn)

ssl - 一个网站的多个IP+域+SSL证书

magento-1.5 - Magento 连接错误 : The 'community' channel is not installed

mysql - Magento - 将 magento 从 1.6.2 更新到 1.7.0.2

http -//和http ://之间的区别

javascript - javascript 如何知道 Rails 3 中当前的语言环境?

linux - 将网络服务器目录从一个操作系统链接到另一个操作系统

php - 在此服务器上找不到所请求的 URL。 .htaccess (MAMP)

php - 如何从地址中删除index.php,同时通过fastcgi将请求重定向到index.php?

http - 任何人都可以提供有关 hash(#) 在 url 中的各种用途的好信息吗?