簡體   English   中英

PHP如何將URL路徑重定向到index.php

[英]PHP how to redirect url path to index.php

我目前有一個網址帶有這種格式的網站

https://website.com/?p=something

其中p是請求的頁面(例如/?p = login)

由於SEO的原因,我希望URL看起來像這樣

https://website.com/login/

我當然可以這樣重定向

Redirect 301 /login/ https://website.com/?p=login

但這會將用戶瀏覽器中顯示的URL更改回帶有參數的URL。

我的問題是,我如何擁有這樣的URL,例如https://website.com/login/但是在PHP中,在index.php內,我可以像以前一樣訪問請求頁面或“路徑”,例如$page = $_GET['p']; 換句話說,我想將URL https://website.com/login/重定向到https://website.com/?p=login但該URL仍顯示為https://website.com/login/

我建議使用.htaccess文件將所有對服務器的請求指向一個文件,例如index.php

# Rewrite Engine ON
RewriteEngine on

# Redirect everything to one file
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

之后,您可以對路由器進行編碼以處理URI組件。

例如有人打電話給站點名稱/登錄

您檢測到/ login並打開所需的頁面

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM