簡體   English   中英

網址重寫無效

[英]URL Rewrites not working

在我的網站上,我試圖將一個長URL重寫為SEO友好的URL。

我有以下代碼,但似乎沒有任何影響! 但是,如果我在htaccess中鍵入dgadgdfsg ,則會引發內部服務器錯誤。 所以我想這與重寫規則有關。

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /missing-people/user-profile.php?userID=$1&firstName=$2&lastName=$3 [L]

我已經確認mod_rewrite已打開。


這是當前網址

http://mysite.com/missing-people/user-profile.php?userID=1&firstName=Liam&lastName=Gallagher

這就是我想要的樣子

http://mysite.com/1/Liam/Gallagher

將您的RewriteRule更改為此(從您的版本中稍作修改)

RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ missing-people/user-profile.php?userID=$1&firstName=$2&lastName=$3 [QSA,L]

如果這樣做不起作用,請嘗試放置R標志進行測試(這將使您的瀏覽器將原始URI更改為: /missing-people/user-profile.php?userID=1&firstName=Liam&lastName=Gallagher

假設您的userID僅由數字組成,並且firstNamelastName僅是字母數字。

RewriteEngine On
RewriteRule /(\d+)/(\w+)/(\w+)/ /missing-people/user-profile.php?userID=$1&firstName=$2&lastName=$3 [L]

一個更嚴格的版本除了可以為所評估的正則表達式的開頭和結尾設置邊界之外,還執行相同的操作。

RewriteEngine On
RewriteRule /^(\d+)\/(\w+)\/(\w+)$/ /missing-people/user-profile.php?userID=$1&firstName=$2&lastName=$3 [L]

暫無
暫無

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

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