BungholeOK
BungholeOK

Reputation: 5

htaccess rewrite traling slash to GET parameter

I use this code to rewrite example.com/kat-something.html to example.com/kat.php?kat=something

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^([^\.]+)-([^/]*)\.html$        $1.php?kat=$2 [QSA]
RewriteRule ^([^\.]+)$                      $1.php [QSA]

But I want ?kat= to be / so example.com/kat/something.html to example.com/kat.php?kat=something so I tried:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^([^\.]+)/(.*)\.html$               $1.php?kat=$2 [QSA]
RewriteRule ^([^\.]+)$                      $1.php [QSA]

But it's not working. So how can I allow / to be an GET name?

Upvotes: 1

Views: 344

Answers (1)

anubhava
anubhava

Reputation: 785611

You can try:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule  ^ - [L]

RewriteRule ^([^/]+)/([^.]+)\.html$  $1.php?$1=$2 [NC,QSA,L]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^./]+)/?$ $1.php [L]

Upvotes: 1

Related Questions