简体   繁体   English

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

[英]what is best way to rewrite url?

This is code my .htaccess file.这是我的 .htaccess 文件的代码。 This is correct code or not?这是正确的代码吗?

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

https://www.example.com/english 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 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 https://www.example.com/english/online-english-typing/Free-Online-Typing-in-english

This is working fine.这工作正常。 but any other way to rewrite?但还有其他方法可以重写吗?

Your Rules for generic URLs looks good to me, you could have them like this, I removed QSA tag from them.您的通用 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