T K
T K

Reputation: 628

Mod Rewrite - Rewrite URL

I've to change my URL from

https://example.com/public/contact.php (the real path)

to

https://example.com/contact

using mod-rewrite.

contact is just a placeholder, it should work with every file in the public directory. Like /home or /login

I was able to remove the file extionsion with this:

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

Upvotes: 0

Views: 72

Answers (1)

Eduardo Escobar
Eduardo Escobar

Reputation: 3389

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/([^\./]+)/?$
RewriteRule .* /public/%1.php [L]

Note: This will not handle two or more level URLs, i.e: https://example.com/contact/form

Upvotes: 1

Related Questions