0

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 ?

RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
  • 1
    Hello Jasveer, it depends on what is your actual requirement. Could you please do let us know from which url to which url you want to rewrites? And also mention what is not working for you for better understanding of your question. – RavinderSingh13 Jan 11 '21 at 05:20
  • No sir this is working fine. but any other way to rewrite ? and my code is correct or not ? – Jasveer Singh Jan 11 '21 at 06:15
  • Your rules look good to me but they are very generic ones, so Rule for `https://www.example.com/english` will match `https://www.example.com/singh` too, so do you want to write rules for specific URL or you need generic ones? – RavinderSingh13 Jan 11 '21 at 06:17
  • yes sir , my URL is generic e.g: https://www.example.com/english , https://www.example.com/punjabi, https://www.example.com/hindi – Jasveer Singh Jan 11 '21 at 06:34

1 Answers1

2

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]
RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
  • ok sir I change it ,and can you explain what is the mean of QSA – Jasveer Singh Jan 11 '21 at 06:48
  • 1
    @JasveerSingh, `The QSA flag means to append an existing query string after the URI has been rewritten.` You could check this answer https://stackoverflow.com/a/16468677/5866580 too. – RavinderSingh13 Jan 11 '21 at 06:50