.htaccess
# Security Headers
<IfModule mod_headers.c>
Header set X-XSS-Protection "1; mode=block"
Header set X-Frame-Options "SAMEORIGIN"
Header set X-Content-Type-Options "nosniff"
Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains"
# Header set Content-Security-Policy ...
Header set Referrer-Policy "same-origin"
Header set Feature-Policy "geolocation 'self'; vibrate 'none'"
</IfModule>
# Index.php default
RewriteEngine On
DirectoryIndex index.php
# Remove .php extension
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.] )$ $1.php [NC,L]
# Force HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Error document handling
ErrorDocument 404 https://landon.pw/404
ErrorDocument 403 https://landon.pw/404
Options -Indexes
如果我嘗試landon.pw/a/,它將重定向到404。如果我嘗試landon.pw/a,它不會。
我相信這個問題是因為我洗掉 php 擴展的方式。當他們去 /a 時,它試圖為 a.php 提供服務,我猜這就是它不會將檔案重定向到 404 的原因。我只是不知道如何規避這個問題。
uj5u.com熱心網友回復:
問題出在您身上,# Remove .php extension因為它正在將任何非檔案請求重寫為等效.php檔案而不檢查檔案是否存在.php。
您可以嘗試使用此代碼來使其正常作業:
# Error document handling
ErrorDocument 404 https://landon.pw/404
ErrorDocument 403 https://landon.pw/404
Options -Indexes
# Index.php default
DirectoryIndex index.php
RewriteEngine On
# Force HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
# Remove .php extension
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(. ?)/?$ $1.php [L]
確保在測驗此更改之前清除瀏覽器快取。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/472439.html
