son 11 Posted July 24, 2011 Report Share Posted July 24, 2011 I have at top of page: if (isset($_GET['id'])) { $id = $_GET['id']; } else { $id = 'normal'; }$getQuery = "SELECT styleName FROM mmstyles WHERE styleID = '$id'"; I have also an entry within .htaccess as: Options +FollowSymlinksRewriteEngine OnRewriteRule ^([^/]+)\/index.php styles/index.php?id=$1 [NC] Now my query does not work as it looks for 'styles' instead of 'normal'. I have use this sort of coding before, only that then I had all in root folder. Now, it has to go in separate folder and as this is the differentiating factor I wonder if the folder name requires a change in .htaccss that I am not aware of. Can you see where I am going wrong?Thanks,Son Quote Link to post Share on other sites
trevelluk 0 Posted July 25, 2011 Report Share Posted July 25, 2011 I think the problem is that after each rewrite, then all of the rewriting rules are by default applied again to the re-written URL, so I think what's happening is something like this:Someone visits mystyle/index.phpThis matches your rewrite rule, and is rewritten to styles/index.php?id=mystyleBUT, this also matches your rewrite rule, and so gets rewritten again to styles/index.php?id=stylesWhich then matches again, but I'd imagine that at this point then the web server sees that it would rewrite to the same URL and so stops to avoid an infinite loop.There's a couple of options:1. Change the rule so that it won't match if ?id is already present. The $ sign means "end of input", so the rule will only match if index.php is the very last thing in the URL: RewriteRule ^([^/]+)\/index.php$ styles/index.php?id=$1 [NC] 2. Prevent multiple rewrites from happening, so that as soon as one re-write has occured, rewriting will stop. You do this by adding the L (for Last) option to your rewrite flags: RewriteRule ^([^/]+)\/index.php styles/index.php?id=$1 [NC,L] Quote Link to post Share on other sites
son 11 Posted August 4, 2011 Author Report Share Posted August 4, 2011 I think the problem is that after each rewrite, then all of the rewriting rules are by default applied again to the re-written URL, so I think what's happening is something like this:Someone visits mystyle/index.phpThis matches your rewrite rule, and is rewritten to styles/index.php?id=mystyleBUT, this also matches your rewrite rule, and so gets rewritten again to styles/index.php?id=stylesWhich then matches again, but I'd imagine that at this point then the web server sees that it would rewrite to the same URL and so stops to avoid an infinite loop.There's a couple of options:1. Change the rule so that it won't match if ?id is already present. The $ sign means "end of input", so the rule will only match if index.php is the very last thing in the URL:RewriteRule ^([^/]+)\/index.php$ styles/index.php?id=$1 [NC] 2. Prevent multiple rewrites from happening, so that as soon as one re-write has occured, rewriting will stop. You do this by adding the L (for Last) option to your rewrite flags: RewriteRule ^([^/]+)\/index.php styles/index.php?id=$1 [NC,L] thanks trevelluk,option 1 does the rewrite ok (option 2 causes an internal server error, so I refrain from using it;-)). Although this did this trick, it showed me that there is another issue now with the rewrite. I run a query as:SELECT styleName FROM mmstyles WHERE styleID = '$id'instead of running this as:SELECT styleName FROM mmstyles WHERE styleID = 'normal' for example it runs it now as SELECT styleName FROM mmstyles WHERE styleID = 'styles'Is there a remedy for this? Although I need 'neat' urls I also need to run my queries ok...Son Quote Link to post Share on other sites
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.