重写 url 的最佳方法是什么?
what is best way to rewrite url?
这是我的 .htaccess 文件的代码。这是正确的代码吗?
RewriteRule ^([a-z_-]+)$ index.php?l= [QSA,L]
https://www.example.com/english
RewriteRule ^([a-z_-]+)/([a-z_-]+)$ index.php?l=&p= [QSA,L]
https://www.example.com/english/online-english-typing
RewriteRule ^([a-z_-]+)/([a-z_-]+)/([A-Za-z_-]+)$ index.php?l=&p=&t= [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= [L]
##For urls like http://localhost:80/english/singh
RewriteRule ^([a-z_-]+)/([a-z_-]+)$ index.php?l=&p= [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=&p=&t= [L]
这是我的 .htaccess 文件的代码。这是正确的代码吗?
RewriteRule ^([a-z_-]+)$ index.php?l= [QSA,L]
https://www.example.com/english
RewriteRule ^([a-z_-]+)/([a-z_-]+)$ index.php?l=&p= [QSA,L]
https://www.example.com/english/online-english-typing
RewriteRule ^([a-z_-]+)/([a-z_-]+)/([A-Za-z_-]+)$ index.php?l=&p=&t= [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= [L]
##For urls like http://localhost:80/english/singh
RewriteRule ^([a-z_-]+)/([a-z_-]+)$ index.php?l=&p= [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=&p=&t= [L]