Roger Wayne Roger Wayne - 3 months ago 24
PHP Question

Convert url slash to parameter

I have to convert url like this

www.domain.tld/long/param


to this

www.domain.tld/long/long.php?l=param


I have CMS on same server and i dont wan't to mess up it's htaccess so this should work only on that specific directory (long).

Tried this but it wont work:
Rewriting a URL to a PHP parameter from inside a subdirectory

Answer

Inside long/.htaccess you can use this rule:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ long.php?l=$1 [L,QSA]