Search code examples
php.htaccessurl-rewriting

How do i make a simple RewriteRule?


Good day guys, im trying to do some friendly url, i have this url:

https://example.com/folder/file.php

And .htaccess code:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]


Options +FollowSymLinks
RewriteRule ^registros/entradas/?$ frmEntradas.php?$1

With .htaccess i want the next url:

https://example.com/folder/anything/anything


Solution

  • You can use the following htaccess code :

    RewriteEngine On
    Options +FollowSymLinks
    RewriteRule ^registros/entradas/?(.*)$ frmEntradas.php?$1 [L]
    #rewrite /file to file.php
    RewriteCond %{REQUEST_FILENAME}.php -f
    RewriteRule ^([^\.]+)$ $1.php [NC,L]
    #rewrite /folder/foobar to /folder/file.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^folder/.* /folder/file.php [L]