Search code examples
.htaccess

Htaccess, go through files until exists?


I have this .htaccess file:

Options +FollowSymLinks
Options -Indexes

RewriteEngine On

RewriteEngine On

RewriteRule \.(png|jpg|gif|jpeg|bmp|ico|flv|mpeg|mp4|mp3|swf|exe|WAgame|wsc|eot|svg|ttf|woff|woff2|rar|wav)$ - []
RewriteRule ^ entryPoint3.php
RewriteRule ^ entryPoint2.php
RewriteRule ^ entryPoint.php

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>

If the entryPoint3.php exists, load it, otherwise load entryPoint2.php otherwise entryPoint.php. How to achieve this?


Solution

  • Have it this way:

    Options +FollowSymLinks -Indexes
    RewriteEngine On
    
    RewriteRule \.(png|jpg|gif|jpeg|bmp|ico|flv|mpeg|mp4|mp3|swf|exe|WAgame|wsc|eot|svg|ttf|woff|woff2|rar|wav)$ - [L]
    
    RewriteRule ^robots\.txt$ / [R,NC,L]
    
    RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
    RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
    
    # if entryPoint3 exists then use it
    RewriteCond %{DOCUMENT_ROOT}/entryPoint3.php -f
    RewriteRule ^ entryPoint3.php [L]
    
    # if entryPoint2 exists then use it
    RewriteCond %{DOCUMENT_ROOT}/entryPoint2.php -f
    RewriteRule ^ entryPoint2.php [L]
    
    # if entryPoint exists then use it
    RewriteCond %{DOCUMENT_ROOT}/entryPoint.php -f
    RewriteRule ^ entryPoint.php [L]
    
    <Files .htaccess>
    Order Allow,Deny
    Deny from All
    </Files>