Check if file exists through . htaccess URL

Asked

Viewed 250 times

0

I have the following situation, I need to check if a particular file exists, based on the URL I am trying to access, if it exists displays normally, otherwise redirects to an error page.

For example:

I have the following file /paginas/contato.php , when calling access URL meusite.com/contact o . htaccess would check if the file exists and load it, otherwise redirect to an error page.

How the . htaccess structure should look to meet this need?

1 answer

0


I found the solution to my problem and I will share here.

RewriteCond %{DOCUMENT_ROOT}/temas/paginas/$1\.php -f [NC] RewriteRule ^(.*)$ /temas/paginas/$1\.php [L]

In my case I needed to check if a particular file existed within the subfolder /themes/pages of the server and display it according to the accessed url.

For example if I access the URL meusite.com.br/contact , he will check the file /themes/pages/contact.php exists, and will carry it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.