Reputation: 219
i am using htaccess for 301 permanent redirect. i have to make a redirect for bima.php to ge.php.so i wrote the below code in htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^bima.php?$ $1/ge.php [NC,R=301,L]
this works properly..whenever i put www.test.com/bima.php in url it will redirect to www.test.com/ge.php the problem is i have to do a 301 redirect for ge.php also.that means whenever www.test.com/gen.php in url it will redirect to www.test.com/bima.php. www.test.com/bima.php needs to redirect to www.test.com/gen.php and vice versa. Any idea?or anyway to do this?
Upvotes: 1
Views: 442
Reputation: 37065
Here is a solution, though I agree with everyone that the basic concept is a bit wacky:
RewriteEngine On
RewriteCond %{ENV:redirected} !=1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^bima.php?$ $1/ge.php [E=redirected:1,NC,R=301,L]
RewriteRule ^ge.php?$ $1/bima.php [E=redirected:1,NC,R=301,L]
By setting the environment variable with the redirect, the second redirect won't trigger, as it will see the redirected rule has been set. Not sure if this will screw up redirects after the initial success, however. Someone else know?
Upvotes: 0
Reputation: 79021
Your redirect rule
RewriteRule ^bima.php?$ $1/ge.php [NC,R=301,L]
RewriteRule ^ge.php?$ $1/bima.php [NC,R=301,L]
Is redirecting in infinite loop. Remove one of them.
No matter what type of logic you use, the redirection you are attempting will end of in loop at one time. So better avoid the need of such requirement.
Here is a PHP Solution
File: ge.php
if($_SESSION['redirected']['from'] != 'bima.php') {
header("location: bima.php");
$_SESSION['redirected']['from'] = 'ge.php';
exit;
}
File: bima.php
if($_SESSION['redirected']['from'] != 'ge.php') {
header("location: ge.php");
$_SESSION['redirected']['from'] = 'ge.php';
exit;
}
Upvotes: 1
Reputation: 3904
bima.php
redirects to ge.php
and ge.php
to bima.php
. This will cause an endless loop. What are you trying to achieve? Why do you want ge.php
redirect to bima.php
and vice-versa?
You should change your design either way.
Upvotes: 0