php - RewriteRule correction -
i've been working on whole day can't figure out. want. both should have urls left /p/test/
or /p/test
, not redirect /p.php?slug=test
(same tag).
example.com/p/test/ -> query example.com/p.php?slug=test example.com/p/test -> query example.com/p.php?slug=test example.com/tag/sometag/ -> query example.com/tag/index.php?tagid=sometag example.com/tag/sometag -> query example.com/tag/index.php?tagid=sometag
what i've tried far:
rewriteengine on rewritecond %{request_filename} !-f rewriterule ^p/([a-z]+)$ p/$1/ [l] rewriterule ^p/([a-z]+)/$ p.php?slug=$1 [l] rewriterule ^tag/([a-z]+)/?$ tag/index.php?tagid=$2 [l]
2nd example:
rewriteengine on rewritecond %{request_filename} !-f rewriterule ^p/([a-z]+)$ p/$1/ [l] rewriterule ^p/([a-z]+)/$ p.php?slug=$1 [l] rewriterule ^tag/([a-z]+)$ tag/$2/ [l] rewriterule ^tag/([a-z]+)/$ /tag/index.php?tagid=$2/ [l]
last example:
rewriteengine on rewritecond %{request_filename} !-f rewriterule ^p/([.*])$ p/$1/ [l] rewriterule ^p/([.*])/$ p.php?slug=$1 [l] rewriterule ^tag/([.*])/?$ tag/index.php?tagid=$1 [l]
non of them working fine except first example first rule (line 3 , 4). 1 had problem, /p/test different /p/test/ there no sign of error whatsoever.
here function proceeding tagid param (and works fine):
public function searchtagid($tag) { if (isset($tag)) { $db = new databaseestablish(); $con = $db->connect(); $sql = $db->dbquery($con, "select * posts tags '%{$tag}%'"); $resultcount = $db->countrows($sql); if ($resultcount == 0) { header('location: ../../index.php'); } while($row = $db->fetcharray($sql)){ echo $row[0]; } } }
.htaccess bellow:
rewriteengine on rewritecond %{request_filename} -f [or] rewritecond %{request_filename} -d rewriterule ^ - [l] rewriterule ^tag/([^/]+)/?$ /tag/index.php?tagid=$1 [qsa,l] rewriterule ^p/([^/]+)/?$ /p.php?slug=$1 [qsa,l]
redirects example.com/p/test/ -> example.com/p.php?slug=test redirects example.com/p/test -> object not found error
redirects example.com/tag/sometag/ -> object not found error redirects example.com/tag/sometag -> object not found error
now, there wanted tell you, please don't blame me, don't want above urls redirect page wrote @ top, rewrite them (do query). example: example.com/p/test/
-> should not redirect example.com/p.php?slug=test
url query (in how can call back-end). url should still example.com/p/test/
(or /p/test). can't explain better, really.
rewriteengine on rewritecond %{request_filename} !-f rewriterule ^/?p/([^/]+)/?$ /p.php?slug=$1 [r=301,l] rewritecond %{request_filename} !-f rewriterule ^/?tag/([^/]+)/?$ /tag/index.php?tagid=$1 [r=301,l]
Comments
Post a Comment