juju
juju

Reputation: 13

Ignoring subfolder in URI

I have a problem with .htaccess configuration. I know how to ignore file extensions (e.g. php). That's my code:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME}.php -f

RewriteRule ^(.*)$ $1.php

But I want to ignore specific a subfolder in the URI. For example, I have a file in example.com/sites/test.php but in the address bar, I just want to type example.com/test. Any ideas?

Upvotes: 1

Views: 109

Answers (2)

anubhava
anubhava

Reputation: 785531

You can use:

RewriteEngine on

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

Upvotes: 0

Tuim
Tuim

Reputation: 2511

You can change the RewriteRule

RewriteRule ^(.*)$ sites/$1.php

Upvotes: 1

Related Questions