重写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]

最新更新