Reputation: 976
I'm trying to redirect users from my main index page back to the index page but with a variable in the url to swap the loaded files. What I'm getting is too many redirects since I've added variables.
Here is what I've done:
RewriteCond %{TIME} <20171201000000
RewriteCond %{REMOTE_ADDR} !^00\.000\.000\.000
RewriteCond %{REQUEST_FILENAME} !(styles|images|javascript).+$
RewriteCond %{REQUEST_URI} !construction.php$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif|css|ttf|woff|js) [NC]
RewriteRule .* /construction [R=302,L]
This part works fine and redirects. However I've added a case switch
function to my index page to eliminate the construction.php
page altogether. So now I've made my redirect into this and it's redirecting too much.
RewriteCond %{TIME} <20171201000000
RewriteCond %{REMOTE_ADDR} !^00\.000\.000\.000
RewriteCond %{REQUEST_FILENAME} !(styles|images|javascript).+$
RewriteCond %{REQUEST_URI} !index.php?redirect=construction$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif|css|ttf|woff|js) [NC]
RewriteRule .* /index.php?redirect=construction [R=302,L]
The reason I am doing this is because I am going to have several redirects from construction
to maintenance
, 404
, etc.
What would cause this to keep redirecting too much when all I did was change the urls?
Just for reference here is the entire index.php
file:
<?php include $_SERVER['DOCUMENT_ROOT'] . "/settings/config.php"; ?>
<body>
<?php include $_SERVER['DOCUMENT_ROOT'] . "/php/header.php"; ?>
<?php
if (! isset($_GET['redirect']))
{
include($_SERVER['DOCUMENT_ROOT'].'/php/index.main.php');
} else {
$redirect = $_GET['redirect'];
switch($redirect)
{
case 'construction':
include($_SERVER['DOCUMENT_ROOT'].'/php/index.construction.php');
break;
case 'maintenance':
include($_SERVER['DOCUMENT_ROOT'].'/php/index.maintenance.php');
break;
}
}
?>
<div class="container-fluid">
<?php include $_SERVER['DOCUMENT_ROOT'] . "/php/footer.php"; ?>
</div>
</body>
</html>
Upvotes: 0
Views: 49
Reputation: 18671
You can't do that:
RewriteCond %{REQUEST_URI} !index.php?redirect=construction$ [NC]
Because query string is not part of the test uri. Use instead:
RewriteCond %{REQUEST_URI} !index\.php$ [NC,OR]
RewriteCond %{QUERY_STRING} !redirect=(?:construction|404)$ [NC]
You can omit the first line, If you use redirect=construction
only for this page.
Upvotes: 2