kalyan02 Posted August 30, 2007 Share Posted August 30, 2007 Hello I am stuck at converting [good url which will be typed] 1) example.com/subject/?param=parameters 2) example.com/subject/ 3) example.com/subject i would like to mod-rewrite this to [it will resolve into the below one at server] 1) example.com/index.php?slug=subject¶m=parameters 2) example.com/index.php?slug=subject 3) example.com/index.php?slug=subject any help would be appreciated thanks in advance Quote Link to comment Share on other sites More sharing options...
effigy Posted August 30, 2007 Share Posted August 30, 2007 I'm not familiar with mod_rewrite, but I think it uses PCRE. Here's an example in PHP; you can try carrying over the pattern: <pre> <?php $tests = array( 'example.com/subject/?param=parameters', 'example.com/subject/', 'example.com/subject', ); foreach ($tests as $test) { echo "<b>$test</b>:<br>"; echo preg_replace('#(?<=/)(\w+)(/)?(?(2)\?(.+))?#', 'index.php?slug=$1&$3', $test); echo '<br>'; } ?> </pre> Quote Link to comment Share on other sites More sharing options...
kalyan02 Posted August 30, 2007 Author Share Posted August 30, 2007 though this works using the preg,.. but it dosent seem to work with .htaccess Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.