我正在嘗試重寫這樣的東西:
https://mywebsite.com/pages/article.html?id=1&title=Title-Goes-Here
進入
https://mywebsite.com/pages/article/1/Title-Goes-Here
使用此重寫規則
RewriteEngine on
RewriteRule ^article/([0-9] )/([0-9a-zA-Z_-] )$ article.html?id=$1&title=$2 [NC,L]
但是,當我在https://htaccess.madewithlove.com/中嘗試此代碼時,它給了我
未滿足此規則。
還在我的網站 htaccess 檔案上嘗試過,但沒有結果。我不知道問題出在哪里。
uj5u.com熱心網友回復:
請不要在在線站點上創建 OR 測驗規則,它們不值得信任,因此請在您的 localhost 或 apache 中測驗這些規則。
使用您顯示的示例/嘗試,請嘗試遵循 htaccess 規則。考慮到您https://mywebsite.com/pages/article.html?id=1&title=Title-Goes-Here在瀏覽器中點擊 URL 并且您希望將其重定向到https://mywebsite.com/pages/article/1/Title-Goes-Here瀏覽器中的 URL。
請確保在測驗您的 URL 之前清除您的瀏覽器快取。
RewriteEngine ON
##External redirect in browser rules here....
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{THE_REQUEST} \s/([^/]*)/([^.]*)\.html\?id=([^&]*)&title=(\S )\s [NC]
RewriteRule ^ /%1/%2/%3/%4? [R=301,L]
##Internal rewrite to html file rules here....
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/?$ $1/$2.html?id=$3&title=$4 [QSA,NC,L]
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/423065.html
標籤:
