Page 1 of 1

Seo Urls

Posted: Tue Jun 17, 2014 2:33 pm
by fremeni
Hi

I'm trying to makes urls much seo compliant.

I need to remove extensions like .html and .php.

I've tried a lot of thinks but nothing works.

For first i need to be sure that the file to be modified is xxx.xxx.xxx.xxx.conf on /etc/nginx/conf.d

Then i saw online that i must add something like this try_files $uri.html $uri $uri/ /index.html;

So my file will be

server {
listen xxx.xxx.xxx.xxx:80 default;
server_name _;
#access_log /var/log/nginx/xxx.xxx.xxx.xxx.log main;
location / {
proxy_pass http://xxx.xxx.xxx.xxx:8080;
try_files $uri.html $uri $uri/ /index.html;
}
}

I restart nginx but nothing happen.

Any idea?

Re: Seo Urls

Posted: Tue Jun 17, 2014 5:20 pm
by demian
wrong way!!!

don't modify config files any time/more

best way:
1. used web ui
2. modify or add template for nginx/apache

for exclude files from nginx use web-->your domain--> edit-->Nginx Extensions

Code: Select all

default:
jpg, jpeg, gif, png, ico, svg, css, zip, tgz, gz, rar, bz2, exe, pdf, doc, xls, ppt, txt, odt, ods, odp, odf, tar, bmp, rtf, js, mp3, avi, mpeg, flv, html, htm
remove/add need some

Re: Seo Urls

Posted: Tue Jun 17, 2014 5:23 pm
by fremeni
Thanks @Damian i will change my approach.

But how i can delete the .html or .php extension on my urls in NGINX ?

Re: Seo Urls

Posted: Tue Jun 17, 2014 5:38 pm
by demian
nginx can't use .php, proxy_pass from apache default for any nginx template

But .html include default because nginx faster use it

Code: Select all

jpg, jpeg, gif, png, ico, svg, css, zip, tgz, gz, rar, bz2, exe, pdf, doc, xls, ppt, txt, odt, ods, odp, odf, tar, bmp, rtf, js, mp3, avi, mpeg, flv, html, htm
remove remove for site html and htm

Code: Select all

jpg, jpeg, gif, png, ico, svg, css, zip, tgz, gz, rar, bz2, exe, pdf, doc, xls, ppt, txt, odt, ods, odp, odf, tar, bmp, rtf, js, mp3, avi, mpeg, flv
and nginx drop it to back-end(apache), this will solw down
But if your HTML files contain php code from this is necessary for correct operation

Re: Seo Urls

Posted: Tue Jun 17, 2014 5:47 pm
by fremeni
I perfeclty undertand now.

No, my html don't contain php but i would use the urls without extension (php and html) because is more seo compliant and is more elegant.

Maybe this will become available on VestaCp when the release will manage php files by Nginx + PHP-FPM ?

Re: Seo Urls

Posted: Tue Jun 17, 2014 6:16 pm
by demian
you need some rewrite rule, but best way use site engine module

for nginx you can modify any default template include him file

template:

Code: Select all

/usr/local/vesta/data/templates/web/nginx/new_default.tpl 
server {
    listen      %ip%:%proxy_port%;
    server_name %domain_idn% %alias_idn%;
    error_log  /var/log/httpd/domains/%domain%.error.log error;

    include %home%/%user%/conf/web/rewrite_nginx.%domain%.conf*;

    location / {
        proxy_pass      http://%ip%:%web_port%;
        location ~* ^.+\.(%nginx_extentions%)$ {
            root           %docroot%;
            access_log     /var/log/httpd/domains/%domain%.log combined;
            access_log     /var/log/httpd/domains/%domain%.bytes bytes;
            expires        max;
            try_files      $uri @fallback;
        }
    }

     location /error/ {
        alias   %home%/%user%/web/%domain%/document_errors/;
    }

    location @fallback {
        proxy_pass      http://%ip%:%web_port%;
    }

    location ~ /\.ht    {return 404;}
    location ~ /\.svn/  {return 404;}
    location ~ /\.git/  {return 404;}
    location ~ /\.hg/   {return 404;}
    location ~ /\.bzr/  {return 404;}

    disable_symlinks if_not_owner from=%docroot%;

    include %home%/%user%/conf/web/nginx.%domain%.conf*;
}
than put file

Code: Select all

touche /home/<username>/conf/web/rewrite_nginx.you_domain.conf
than add rule in that file

Code: Select all

location  ~<need url or reg_exp> {
proxy_pass      http://real_url;
}
NOTE: name_template.tpl and name_template.stpl is one template need modify/copy both file if you add some general directive

than in web ui change template for your site new_default