我.htaccess在我的域檔案夾中的檔案中創建規則。
我在服務器上的網址是:
https://www.everyoneknows.com.my/customer/?loc=dashboard
我想將 url 更改為:
https://www.everyoneknows.com.my/customer/dashboard/
在.htaccess檔案中,我寫的規則是:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^everyoneknows\.com\.my [OR,NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.everyoneknows.com.my/$1 [R,L]
##External redirect to /customer/dashboard url rules here.
RewriteCond %{QUERY_STRING} ^loc\=dashboard$
RewriteRule ^customer/$ https://www.everyoneknows.com.my/customer/dashboard/? [R=301,L]
并顯示錯誤訊息:
Not Found
The requested URL was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

希望有人可以指導我如何更正我的重寫 url 規則。謝謝。
原始結果:

更新 1

uj5u.com熱心網友回復:
您需要一個將舊 URL 重定向到新 URL 的重定向規則和一個內部重寫規則來處理漂亮的 URL:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^everyoneknows\.com\.my [OR,NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^ https://www.everyoneknows.com.my%{REQUEST_URI} [R=301,NE,L]
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/ (customer)/\?loc=([^\s&] ) [NC]
RewriteRule ^ /%1/%2/? [R=301,L,NE]
# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(customer)/([\w-] )/?$ $1/?loc=$2 [L,QSA,NC]
這假設customer/子目錄中沒有 .htaccess 。在測驗此更改之前,請確保清除瀏覽器快取。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/358468.html
上一篇:重寫URL子目錄
