簡體   English   中英

如果 url 包含單詞而不使用 htaccess 更改 url,則重定向

[英]Redirect if url contains word without changing url using htaccess

重定向如果 url 包含特定單詞而不更改它。

例如: http://localhost/APIs/student

應該重定向到“ http://localhost/APIs/

我嘗試了很多事情,其中​​之一如下:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^[A-Z]{10,}\s/+index\.php\?page=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteRule ^([a-z0-9-]+)/?$ /APIs/index.php?page=$1-10 [QSA,L,NC] 

如果我在斜杠后的鏈接中傳遞多個參數,則上述代碼段將失敗。

這是規則

RewriteEngine on
RewriteRule ^APIs/(.*)$ APIs/index.php?page=$1 [NC,END]

如果您要求

http://localhost/APIs/student/test

您將被內部重定向到(您將看到與上面相同的網址)

http://localhost/APIs/index.php?page=student/test

index.php文件中,使用$_GET["page"]獲取student/test ,您可以根據此決定在頁面中顯示的內容。

暫無
暫無

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

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