簡體   English   中英

重寫 url 的最佳方法是什么?

[英]what is best way to rewrite url?

這是我的 .htaccess 文件的代碼。 這是正確的代碼嗎?

RewriteRule ^([a-z_-]+)$ index.php?l=$1 [QSA,L]

https://www.example.com/english

RewriteRule ^([a-z_-]+)/([a-z_-]+)$ index.php?l=$1&p=$2 [QSA,L]

https://www.example.com/english/online-english-typing

RewriteRule ^([a-z_-]+)/([a-z_-]+)/([A-Za-z_-]+)$ index.php?l=$1&p=$2&t=$3 [QSA,L]

https://www.example.com/english/online-english-typing/Free-Online-Typing-in-english

這工作正常。 但還有其他方法可以重寫嗎?

您的通用 URL 規則對我來說看起來不錯,您可以像這樣擁有它們,我從它們中刪除了 QSA 標記。

RewriteEngine ON
##For urls like http://localhost:80/english
RewriteRule ^([a-z_-]+)$ index.php?l=$1 [L]

##For urls like http://localhost:80/english/singh
RewriteRule ^([a-z_-]+)/([a-z_-]+)$ index.php?l=$1&p=$2 [L]

##For urls like http://localhost:80/english/online-english-typing/Free-Online-Typing-in-english
RewriteRule ^([a-z_-]+)/([a-z_-]+)/([A-Za-z_-]+)$ index.php?l=$1&p=$2&t=$3 [L]

暫無
暫無

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

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