0

I've currently got an nginx config that is working for all intents and purposes apart from a small issue when a url doesn't include a trialing slash.

The website is Magento held within a subdirectory (the relative url issue alone was a nightmare as rest of websites run without subdirectories). What through up the issue was query strings being appended without the trialing slash.

However, for example:

http://www.example.com/magento/category/

Will correctly direct to the appropriate page, however when I remove the trialing slash from the url, it redirects to http://www.example.com/category.

So far I have added some code into Magento's core to intercept and add a trialing slash to the end of each url and in between a query string.

However, I suspect this is an nginx problem, and solving it via code isn't exactly the ideal way of doing it.

Below is the nginx configuration I have for the subdirectory:

location ~ fr/ {
location ~ (/(app/|includes/|/pkginfo/|var/|report/config.xml)|/\.svn/|/.hta.+) {
   deny all;
}

location ~* \.(js|css)$ {
     expires 30d;
}

location ~ (\.php|/downloader/?|/report/?)$ {
  if ($request_uri ~ /(downloader|report)$){ # no trailing /, redirecting
    rewrite  ^(.*)$ $1/ permanent;
  }
  fastcgi_index index.php;
  include /etc/nginx/fastcgi_params;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  if (-e $request_filename) { # check if requested path exists
    fastcgi_pass belgiumnlbackend;
  }
}

index index.php;
try_files $uri $uri/fr/ @handler;
expires 30d;
   # set expire headers
   if ($request_uri ~* "\.(ico|css|js|gif|jpe?g|png)$") {
       expires max;
   }
   # set fastcgi settings, not allowed in the "if" block
   include /etc/nginx/fastcgi_params;
   fastcgi_param SCRIPT_FILENAME  $document_root/fr/index.php;
   fastcgi_param SCRIPT_NAME  /fr/index.php;
   fastcgi_param SERVER_PORT 80;
   fastcgi_param PRODUCTION true;
   fastcgi_param HTTPS $sslmode;
   fastcgi_index /fr/index.php;
   fastcgi_param MAGE_RUN_CODE redacted;
   fastcgi_param MAGE_RUN_TYPE store;
   # rewrite - if file not found, pass it to the backend
   if (!-f $request_filename) {
       fastcgi_pass belgiumnlbackend;
       break;
   }
}

The root location works perfectly fine, its just this subdirectory one that is the issue. Is there anything I am doing glaringly wrong here?

I've had a quick look over serverfault and can't find anything that stands out to me as a resolution to this issue, although I may be being completely blind so apologies if this is a duplicate question.

Thanks in advance!

evensis
  • 1
  • 2

0 Answers0