nginx config,重写一个包含目录的URI

时间:2014-09-09 03:31:17

标签: nginx

我在我的nginx中有一个干净的url写配置,它将所有内容重写为/index.php/everything 有一个小问题, 它不会将/ sitemap重写为/index.php/sitemap,因为根目录中有一个名为“sitemap”的目录。 如何“强制”nginx重写/站点地图而不是读取目录?

这是我配置文件的一部分。

 location /sitemap {
    rewrite /sitemap /index.php/sitemap last;
 }
 location / {
    index index.php; ## Allow a static html file to be shown first
    try_files $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler
    expires 30d; ## Assume all files are cachable
}

## These locations would be hidden by .htaccess normally
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; }

location /var/export/ { ## Allow admins only to view export folder
    auth_basic           "Restricted"; ## Message shown in login window
    auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword
    autoindex            on;
}

location  /. { ## Disable .htaccess and other hidden files
    return 404;
}

location @handler { ## Magento uses a common front handler
    rewrite / /index.php;
}

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

location ~ .php$ { ## Execute PHP scripts
    if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss

    expires        off; ## Do not cache dynamic content
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index  index.php;
    #fastcgi_param  HTTPS $fastcgi_https;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_param  MAGE_RUN_CODE default; ## Store code is defined in administration > Configuration > Manage Stores
    fastcgi_param  MAGE_RUN_TYPE store;
    include        fastcgi_params; ## See /etc/nginx/fastcgi_params
}

1 个答案:

答案 0 :(得分:2)

好吧,你的配置看起来是正确的(至少是已发布的部分)并且重写规则必须有效,你可以在任何位置{}配置之前尝试这样重写:

rewrite ^/sitemap(.*)$ /index.php/sitemap last;