从网站网址隐藏.html文件扩展名

时间:2018-05-23 19:45:03

标签: nginx file-extension

我试过这个:http://www.tweaktalk.net/60/nginx-remove-php-file-extension-from-url但它对我来说并不适合。我收到错误404或错误505

我在nginx服务器上使用Digital Ocean托管。

1 个答案:

答案 0 :(得分:0)

如果有人想知道我是如何解决的:

我已经去了目录 /etc/nginx/conf.d ,在那里创建了一个名为' domain.trade.conf的文件夹' ,例如,如果我的域名为 example.com ,则文件夹名称为 example.com.conf

在此文件中,我添加了以下代码:

server {
    listen       80;
    server_name  example.com; #Domain
    root         /var/www/html; #The place of your site files
    access_log   /var/www/html/logs/access.log; #Where to log the accesses
    error_log    /var/www/html/logs/error.log; #Where to log the errors

    location / { 
        try_files $uri $uri/ @htmlext;
    }   

    location ~ \.html$ {
        try_files $uri =404;
    }   

    location @htmlext {
        rewrite ^(.*)$ $1.html last;
    } 
}

希望我帮助过你。

相关问题