I want all requests to be transferred via a PHP file.
My .htaccess file:
RewriteEngine on
RewriteRule . /test.php [L,NE]
And My PHP Code:
<?php
header("Location: ".$_SERVER['SCRIPT_URI']);
?>
But without a doubt the result of this code is an infinite loop. The request is given to PHP yy .htaccess. and when PHP redirects the user, the user goes to .htaccess again and again.
My Answer:
To avoid the infinite loop, you can add a condition in your .htaccess file to only redirect requests that are not already going to the test.php file. Here's an updated version of your .htaccess file:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/test.php
RewriteRule ^ /test.php [L,NE]
This will only redirect requests that are not already going to test.php, preventing the infinite loop.
Rate this post
3 of 5 based on 7757 votesComments