apache.htaccessmod-rewriteurl-rewritinglightspeed

beautify url from art.php?id=51 to art/51


want to beautify an url from:
https://abuena.net/art.php?id=51
to
https://abuena.net/art/51

here is my try, without success, simply is ignored

RewriteEngine on
RewriteRule ^([a-zA-Z0-9_]+)$ /$1/ [R]
RewriteRule ^([a-zA-Z0-9_]+)/$ /art.php?id=$1

My hosting provider says that my server is not Apache but LSWS - LiteSpeed WebServer - and that is probably problem in my syntax.

Any help?


Solution

  • Could you please try following. Considering that you need to hit URLs like https://abuena.net/art/51 in your browser. Please make sure to clear your browser cache before testing your URLs.

    RewriteEngine ON
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]*)/(.*)/?$ $1.php?id=$2
    


    EDIT: In case you are hitting URL like https://abuena.net/art.php?id=51 in your browser then try following once.

    RewriteEngine ON
    RewriteCond %{REQUEST_URI} \s/([^.]*)\.php\?id=(\d+)\s [NC]
    RewriteRule ^ http://%{HTTP_HOST}/%1/%2 [R=301]
    RewriteRule ^([^/]*)/(.*)/?$ $1.php?id=$2 [L]