我正在嘗試將所有 root 用戶重定向到特定鏈接,例如:example.com到example.com/en1哪個index.php檔案,所以如果任何用戶型別example.com/en2 or en3 or en100將重定向到example.com/en1
我試過這段代碼
if (strpos($_SERVER['REQUEST_URI'], "en1") == false){
header('Location: en1');
}
但問題是,當我輸入en2 or en100它顯示 404 錯誤未重定向到en1
也試過htaccess
RedirectMatch ^/$ /en1
RewriteRule en1 index.php
但沒有運氣!
我如何解決它?
uj5u.com熱心網友回復:
你可以RewriteRules這樣使用:
RewriteEngine On
#redirect / to /en1
RewriteRule ^$ https://example.com/en1 [R,L]
#redirect /en123 to /en1
RewriteCond %{REQUEST_URI} !/en1$
RewriteRule ^en[0-9] https://example.com/en1 [L,R]
讓我知道它是如何為您作業的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/435976.html
