SmoothLinux Blog

Nibbleblog Nginx Removing Trailing Slash

26 November, 2014 | nginx

I switched to Nibbleblog from Pico for the SEO options and the administration options. However when I switched I wanted to keep my old post SEO. However Nibbleblog adds a trailing slash to all its links once you enable Friendly URLs in Nibbleblog. If you need any help getting Friendly URLs working with Nibbleblog my suggestion would be to take a look at  the following blog post http://kbeezie.com/category/nibbleblog/ . I got the base rules from the blog post I linked and edited them to removing the trailing slash.

Why Do You Care About The Trailing Slash ?

My site is indexed by google and bing bots and if you do not fix this it will be SEO nightmare. The search bots will index my site and create another post with the same information with just a trailing slash. Which in turn counts against your search ranking.

Nginx Rewrite Rule Changes To Remove The Trailing Slash

I'm not going to post the full nginx configuration as the blog post above has that covered very well. All I needed to do was to edit the rewrite rule section to remove the trailing slash.

 location @nibbleblog {
rewrite ^/category/(.*[^/]+)page-([0-9+])$ /index.php?controller=blog&action=view&category=$1&number=$2 last;
rewrite ^/category/(.*[^/]+)$ /index.php?controller=blog&action=view&category=$1&number=0 last;
rewrite ^/tag/(.*[^/]+)/page-([0-9]+)$ /index.php?controller=blog&action=view&tag=$1&number=$2 last;
rewrite ^/tag/(.*[^/]+)$ /index.php?controller=blog&action=view&tag=$1&number=0 last;
rewrite ^/page-(.*[0-9]+)$ /index.php?controller=blog&action=view&number=$1 last;
rewrite ^/post/(.*[^/]+)$ /index.php?controller=post&action=view&post=$1 last;
rewrite ^/post-(.*[0-9]+)/(.*)$ /index.php?controller=post&action=view&id_post=$1 last;
rewrite ^/page/(.*[^/]+)$ /index.php?controller=page&action=view&page=$1 last;
rewrite ^/feed$ /feed.php last;
rewrite ^/(.*[^/]+)$ /index.php?controller=page&action=$1 last;
rewrite ^(.+)/+$ $1 permanent; }

Comments

comments powered by Disqus