1

I have a site with the following structure:

/
|
folder1
    |
    index.php
    index.html

Default is to open index.php but if user is not logged in I do:

header('Location: '.$domain.'/folder1/index.html');
exit;

This works fine for any folder but for folder1 I have also an .htaccess (locate at the root of the site) to handle some logics on index.php. The .htaccess is the following:

RewriteEngine on
RewriteBase /
RewriteRule \.(php)$ - [L]
RewriteRule ^folder1/([^/]+)/?$ folder1/index.php?source=$1 [L]

I need help to add a rule so that if I request index.html it gets served without inconvenients. Otherwise now the access.log returns:

10.211.55.2 - - [14/Jan/2021:20:15:50 +0100] "GET /folder1/index.html HTTP/1.1" 302 589 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:84.0) Gecko/20100101 Firefox/84.0"

and keeps an infinite loop that ends with firefox saying "this site is not redirecting properly".

For any other folder where the .htaccess is not applied access.log shows the correct behaviour:

10.211.55.2 - - [14/Jan/2021:21:30:52 +0100] "GET /folder2/ HTTP/1.1" 302 4230 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:84.0) Gecko/20100101 Firefox/84.0"

and the browser correctly displays the index.html

How do I fix the .htaccess to handle the redirect from index.php to index.html?

1 Answer 1

2
RewriteRule \.(php)$ - [L]

You could just add another exception, just as you have done for .php files. For example, after the rule above, but before your rewrite to index.php:

RewriteRule ^folder1/index\.html$ - [L]

Any request for /folder1/index.html goes no further, so is not rewritten to index.php by the directive that follows (so no redirect occurs).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.