隐藏站点 url 的 .html 文件扩展名
Hiding .html file extension from site url
我试过这个:http://www.tweaktalk.net/60/nginx-remove-php-file-extension-from-url 但它对我来说不太管用。我收到错误 404 或错误 505
我正在使用带有 nginx 服务器的 Digital Ocean 托管。
如果有人想知道我是如何解决这个问题的:
我去了目录 /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 ^(.*)$ .html last;
}
}
希望对你有所帮助。
我试过这个:http://www.tweaktalk.net/60/nginx-remove-php-file-extension-from-url 但它对我来说不太管用。我收到错误 404 或错误 505
我正在使用带有 nginx 服务器的 Digital Ocean 托管。
如果有人想知道我是如何解决这个问题的:
我去了目录 /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 ^(.*)$ .html last;
}
}
希望对你有所帮助。