I set up my magento store running on LEMP server. Every thing works fine except the url rewrite of category does not work. If I use the url http://mystore.com/catalog/category/view/id/3, then I can see the category view page. But if I click the category on the top menu and its url is rewritten to http://mystore.com/website-sale.html. Then the category page is missing. I got the '404' error message.
Magento – category url rewrite doesn’t work when magento running on nginx
nginxurl
Related Solutions
I've posted a working sample config below. Included is a set of rewrite rules that allows us to serve up static html pages from the "static" directory. If we're advertising a product like http://yourdomain.com/super-popular.html that we expect many thousands of concurrent hits to, we may opt to save the html of super-popular.html in the static directory to skip php entirely. Nginx absolutely crushes Apache in serving up these pages in particular.
We've experienced rock solid performance with the config below.
server {
listen 80 default ;
server_name www.yourdomain.com;
root /var/www/production/web;
## allow for html source of super high volume product pages to be put in "static" directory and served without php
if ($http_host ~ "^(.*)yourdomain.com"){
set $rule_0 1;
}
if ($uri ~ "^(.*)$"){
set $rule_0 2$rule_0;
}
if ($http_referer !~* ".*yourdomain.com"){
set $rule_0 3$rule_0;
}
if (-f $document_root/static$request_uri){
set $rule_0 4$rule_0;
}
if ($rule_0 = "4321"){
rewrite ^/.*$ /static/$request_uri last;
}
## Images and static content is treated different
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ {
access_log off;
expires 30d;
root /var/www/production/web/;
}
location / {
index index.html 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 /nginx-config/ { deny all; }
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 127.0.0.1:9000;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_read_timeout 120;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE yourdomain_store;
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params; ## See /etc/nginx/fastcgi_params
}
access_log /var/log/nginx/yourdomain.com-access_log combined;
}
How to Remove index.php from Magento URLs
Magento is a fantastic platform for selling online, arguably the best, but there’s one thing that has always left me frustrated as an SEO… That pesky index.php directory in the URL of ALL internal pages – nightmare!
There’s no benefit to them.
They’re bad for SEO, bad for site structure and consistency, and then they’re even worse for a clean URL freak like me. They’re not sexy enough. Let’s clean things up.
SEO Friendly Magento URLs in Two Steps
Fortunately, whilst I was doing a Magento store for a client recently, I did a little bit of digging and found a pretty straightforward solution to the issue. It involves a couple of changes to the Magento admin settings and the addition, or modification, of a simple .htaccess file to sort out of the rewriting of their standard store URLs.
Follow the simple steps below and you’ll be a step closer to SEO success with your own Magento store, and your SEO won’t have an excuse for decreased relevancy.
1) Let’s Change a Setting, Admin
The first thing you need to do is to login to your Magento admin panel (index.php/admin) in order to change a very simple setting which will let Magento know that you intend to use URL rewriting throughout your store rather than their ugly default URLs.
Login, and change this setting:
Go to System > Configuration > Web > Search Engine Optimization
Use Web Server Rewrites: YES
That was easy, wasn’t it? Okay, now for the final step.
2) Let’s Use a .htaccess File to Rewrite the URLs
The final step involves creating a .htaccess file in the Magento installation folder in order to compliment the settings you changed within your admin settings earlier, and this will actually rewrite the URLs. Choose the applicable .htaccess version below.
If your Magento store is installed in root (public_html), use this:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
If your Magento store is installed in a subfolder (public_html/shop), use this:
RewriteEngine On
RewriteBase /shop/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /shop/index.php [L]
You’re done – hope that helps!
It’ll definitely stop your SEO from pulling out his or her hair.
Let me know in the comments below if you use this or run into any issues!
Best Answer
Magento explains how to configure nginx
I thought about shortening the config, but I think this is a bad idea. I don't have any idea about nginx but afaik .htaccess doesn't work, so you have to configure rewrite to
index.php
by yourself.But still have a look on the link for the global config!