apache - Regex redirecting page to unwanted page -
i using htaccess clean url, following rule profile page
rewriterule ^([0-9a-z]+)$ profile.php?user=$1
but have other pages followers, following of loggedin user can see followers @ /followers
page , rule is
rewriterule ^following$ follow.php?follow=following rewriterule ^followers$ follow.php?follow=followers
but when go /followers
getting redirected profile.php
(first rule above), can see in first rule after domain name localhost/text_that_comes_here
goes profile.php
what solution /followers
, other pages redirected correctly.
you should put more specific rules before more generic ones.
in case, rules ^following$
, ^followers$
more specific ^([0-9a-z]+)$
...
cause "following" , "followers" catched first rule ^([0-9a-z]+)$
, , therefore redirecting profile.php
reordering .htaccess following should trick:
rewriterule ^following$ follow.php?follow=following rewriterule ^followers$ follow.php?follow=followers rewriterule ^([0-9a-z]+)$ profile.php?user=$1
edit: answer comment, here's method use programmatically:
*however, it’s kind of hack , wouldn’t use permanent fix.
since redirect profile.php?user=following
(or profile.php?user=followers
), add condition in beginning of profile.php
page , check if parameter $_get["user"]="following"
(or "followers"). like:
if ($_get["user"]="following" || $_get["user"]="followers") { $_get["follow"]=$_get["user"]; //set parameter required in “follow.php” include("follow.php"); exit; }
that implies won’t able have user named following
or follower
, shouldn’t happen anyway… still.
Comments
Post a Comment