Search code examples
.htaccessparameterspretty-urls

How to set pretty url with .htaccess for different parameters


I'm trying to set pretty URLs for my website. Thanks to @JonLin I managed to change site with two parameters. The other thing I want to do is make it work for one parameter as well. Here is the code

RewriteEngine On

RewriteCond %{THE_REQUEST} \ /+devplus0/index\.php\?key=([^&]+)&lang=([^&\ ]+)
RewriteRUle ^ /%1/%2? [L,R]

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

You can check the site prettyurl from http://www.devplus.co/english/about-us


Solution

  • For one param, add:

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