Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
258 views
in Technique[技术] by (71.8m points)

apache - what is best way to rewrite url?

This is code my .htaccess file . This is correct code or not ?

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

This is working fine. but any other way to rewrite ?

question from:https://stackoverflow.com/questions/65661654/what-is-best-way-to-rewrite-url

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your Rules for generic URLs looks good to me, you could have them like this, I removed QSA tag from them.

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]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...