因此,我一直在努力讓我的網站以以下方式運作:
example.com 顯示 example.com/index.html
example.com/test 顯示 example.com/test.html
等等。
所以我目前的設定檔是這樣的:
server {
listen 80;
listen [::]:80;
server_name example.com;
root /var/www/html;
index index.html index.php;
location / {
try_files $uri.html $uri $uri/ @htmlext;
}
location ~ \.html$ {
try_files $uri =404;
}
location @htmlext {
rewrite ^(.*)$ $1.html last;
}
error_page 404 /404.html;
}
所以我昨天一直在谷歌搜索,但無法讓它工作。所以提前致謝!
答案1
server {
listen 80;
listen [::]:80;
server_name example.com;
root /var/www/html;
index index.html index.php;
location / {
try_files $uri $uri.html $uri/ /index.html;
}
error_page 404 /404.html;
}
答案2
下面的配置為您提供以下內容:
curl http://example.com/test
--> 輸出:test.html 的內容
curl http://example.com/
--> 輸出:index.html的內容
server {
listen 80;
listen [::]:80;
server_name example.com;
root /var/www/html;
index index.html index.php;
location /test {
try_files $uri.html $uri $uri/;
}
location / {
try_files $uri.html $uri $uri/;
}
location ~ \.html$ {
try_files $uri =404;
}
error_page 404 /404.html;
}