1

original url - example.com/art.php?a=lorem
want to be visible as - example.com/art/lorem
litespeed server - htaccess is enabled

RewriteEngine ON
RewriteRule ^art/(.*)$ /art.php?a=$1 [L]

doesn't work
url is still - example.com/art.php?a=lorem
pls help

qadenza
  • 9,025
  • 18
  • 73
  • 126

1 Answers1

1

You just have a rewrite rule to rewrite example.com/art/lorem but you are missing a redirect rule to redirect example.com/art.php?a=lorem to example.com/art/lorem.

You may use:

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/+art\.php\?a=([^\s&]+) [NC]
RewriteRule ^ /art/%1? [R=301,L]

RewriteRule ^art/([\w-]+)/?$ art.php?a=$1 [L,QSA]

THE_REQUEST variable represents original request received by Apache from your browser and it doesn't get overwritten after execution of other rewrite directives. Example value of this variable is GET /index.php?id=123 HTTP/1.1

References:

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • 1
    it works, thanks a lot, especially for your explanation. I'm totally confused about all regarding `.htaccess` and can't find any reference for beginners. BTW see this one line but similar solution - `https://css-tricks.com/snippets/htaccess/remove-file-extention-from-urls/` – qadenza Apr 02 '21 at 21:48
  • I have added bunch of reference links in my answer. – anubhava Apr 02 '21 at 21:50