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]


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


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


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

1 answer

  • answered 2021-01-11 06:39 RavinderSingh13

    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]