0

I would need such a .htaccess file, which enables me direct access to some files by extension (images), and in any other case it checks if entryPoint2.php exists, if does, execute that file, if not, executes entryPont.php. This is what I made so far:

Options +FollowSymLinks
Options -Indexes

RewriteEngine On
RewriteCond %{REQUEST_URI} !(\.png|\.jpg|\.gif|\.jpeg|\.bmp|\.ico|\.flv|\.mpeg|\.mp4|\.mp3|\.swf)$
RewriteCond %{REQUEST_URI} !^/forum
RewriteCond %{REQUEST_URI} !^/assets/downloads
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/entryPoint2.php -f
RewriteRule ^(.*)$ entryPoint2.php [QSA,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ entryPoint.php [QSA]
RewriteRule ^robots\.txt$ http://www.example.com [R,NE,L]
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST} [L,R=301]
<Files .htaccess>
Order Allow,Deny
Deny from All
</Files>

images works, but I get "forbidden" error, it looks for index.php

John Smith
  • 6,129
  • 12
  • 68
  • 123
  • 1
    use the copy of http://stackoverflow.com/questions/4365129/htaccess-remove-index-php-from-url – Jagadeesh Dec 14 '16 at 12:00
  • 1
    If I understand correctly, other than those files with the specified extensions, you want to serve either entryPoint.php or entryPoint2.php based on the existence of entryPoint2.php, without redirecting. Is that correct? – Rei Dec 16 '16 at 11:07
  • yes "11 more to go" – John Smith Dec 16 '16 at 15:35
  • 1
    Then, the link provided by @Jagadeesh doesn't help, because it is all about redirecting. I'll post an answer later. – Rei Dec 16 '16 at 15:57

1 Answers1

1

Your requirement turns out to be less complex than I initially thought. What you need is a white list and a simple file check.

This should do:

RewriteEngine on
RewriteRule \.(png|jpg|gif|jpeg|bmp|ico|flv|mpeg|mp4|mp3|swf)$ - [L]
RewriteCond %{DOCUMENT_ROOT}/entryPoint2.php -f
RewriteRule ^ entryPoint2.php [L]
RewriteRule ^ entryPoint.php

Line by line explanation:

  • Line 1 is self-explanatory.
  • Line 2 is an extension-based while list. It makes Apache serve files matching those extensions immediately, ignoring the rest of the .htaccess.
  • Line 3 checks the existence of entryPoint2.php. If, for instance, DOCUMENT_ROOT is /foo/bar, it checks if /foo/bar/entryPoint2.php exists.
  • Line 4 will serve entryPoint2.php if line 3 evaluates to true, ignoring the rest of the .htaccess.
  • Line 5 serves entryPoint.php for any other case.

There you go.

Rei
  • 6,263
  • 14
  • 28