Search code examples
.htaccesspretty-urls

.htaccess prettyurl with parameters can't make it work


I'm trying to make a prettyurl like from: example.com/index.php?key=test&lang=eng to example.com/test/eng

I've searched a lot of code samples on the net but I can't seem to make it work. This is what I'm working on right now.

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)\$ index.php?key=$1&lang=$2 [L]

Solution

  • You don't want to escape the $ symbol. Try:

    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} \ /+index\.php\?key=([^&]+)&lang=([^&\ ]+)
    RewriteRUle ^ /%1/%2? [L,R]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]*)/([^/]*)/?$ index.php?key=$1&lang=$2 [L,QSA]