我正在嘗試在 CloudWays 服務器中創建一個對 SEO 友好的 URL,但它不起作用。另外,當我在 localhost 或 Cpanel 中嘗試它時,它作業正常。
謝謝!
這是我的 .htaccess 檔案代碼:-
Options MultiViews
RewriteEngine On
# Set the default handler
DirectoryIndex index.php index.html index.htm
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /index.php/$1 [L]
RewriteRule ^validate/([a-zA-Z0-9-/] )$ search.php?phoneNumber=$1
RewriteRule ^validate/([a-zA-Z-0-9-] )/ search.php?phoneNumber=$1
這是主要鏈接:-
https://example.com/search.php?phoneNumber=16503858068
我想要這樣:-
https://example.com/validate/16503858068
uj5u.com熱心網友回復:
看看RewriteRule (.*) /index.php/$1 [L]。
該L選項意味著決議器在匹配時停止在此重定向規則上。由于(.*)將匹配應用規則的所有內容,并且永遠不會應用以下規則。
要解決此問題,您可以在此規則之前添加您自己的規則,但請確保同時使用該L標志,否則(.*)規則將再次覆寫它。
這也在這里得到了回答: multiple rewriterules
uj5u.com熱心網友回復:
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*) /index.php/$1 [L] RewriteRule ^validate/([a-zA-Z0-9-/] )$ search.php?phoneNumber=$1 RewriteRule ^validate/([a-zA-Z-0-9-] )/ search.php?phoneNumber=$1
您的規則順序錯誤。最后兩條規則(可以合并為一條)永遠不會被處理,因為表單的 URL被前一條規則/validate/16503858068路由到/index.php。
試試這樣:
# Disable MutliViews
Options -MultiViews
RewriteEngine On
# Set the default handler
DirectoryIndex index.php index.html index.htm
RewriteRule ^validate/([a-zA-Z0-9-] )/?$ search.php?phoneNumber=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /index.php/$1 [L]
注意L第一條規則上的標志。
此外,您可能應該禁用 MultiViews。出于某種原因,您明確啟用了此功能?
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/346088.html
