我想使用 .htaccess 洗掉 URL 中的 .html 擴展名,并且能夠在末尾帶有或不帶有斜杠的情況下訪問 URL。現在,當我最后用斜杠呼叫頁面時,我得到 500 Internal Server Error
我的 .htaccess 代碼:
DirectorySlash Off
Options FollowSymLinks -MultiViews -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.] )\.html [NC]
RewriteRule ^ %1 [R,L,NC]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [L]
uj5u.com熱心網友回復:
像這樣:
DirectorySlash Off
Options FollowSymLinks -MultiViews -Indexes
RewriteEngine On
# To externally redirect /dir/file.html to /dir/file
RewriteCond %{THE_REQUEST} \s/ (. ?)\.html[\s?] [NC]
RewriteRule ^ /%1 [R=302,NE,L]
# To internally forward /dir/file to /dir/file.html
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^(. ?)/?$ $1.php [L]
一些 Apache 實作可以解決錯誤%{REQUEST_FILENAME},因此最好使用%{DOCUMENT_ROOT}.
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/503689.html
標籤:.htaccess 重定向 改写 url重写 阿帕奇2
上一篇:我怎樣才能讓它停止計數?
