Check if file exists through URL with .htaccess

0

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

For example:

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

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

    
asked by anonymous 13.09.2017 / 21:11

1 answer

0

I found the solution to my problem and I'll share it 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 certain file existed within the / themes / pages subfolder of the server and display it according to the url accessed.

For example, if I access the URL myite.com/contact , it will check if the /temps/pages/contact.php file exists, and goes loads it.

    
14.09.2017 / 13:05