mikejv Posted January 16, 2020 Share Posted January 16, 2020 Hi all, This is a strange one that's really bugging me. I have some very simple HTACCESS code: RewriteEngine On RewriteRule ^(.*?)/?$ index.php?folder=$1 So, visiting mysite.com/admin should point to mysite.com/index.php?folder=admin However, when using print_r( $_GET ) on index.php, I get: Array ( [folder] => index.php ) I'm getting index.php returned instead of admin, any ideas? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/309873-rewriterule-not-working-right/ Share on other sites More sharing options...
requinix Posted January 16, 2020 Share Posted January 16, 2020 This is one of those things people tend to forget: mod_rewrite will apply your rules, but it starts over again with the new URL too. Use a couple RewriteConds to make sure that the thing you are rewriting does not exist as a file or directory. Quote Link to comment https://forums.phpfreaks.com/topic/309873-rewriterule-not-working-right/#findComment-1573571 Share on other sites More sharing options...
mikejv Posted January 16, 2020 Author Share Posted January 16, 2020 Hey, thanks for your response. I used RewriteCond to ignore index.php to see if that solved anything, but it didn't, and admin doesn't exist as a file or directory. Quote Link to comment https://forums.phpfreaks.com/topic/309873-rewriterule-not-working-right/#findComment-1573572 Share on other sites More sharing options...
requinix Posted January 16, 2020 Share Posted January 16, 2020 1 hour ago, mikejv said: I used RewriteCond to ignore index.php to see if that solved anything, That could work. If it didn't then there was a problem with it. 1 hour ago, mikejv said: and admin doesn't exist as a file or directory. Well yes, but this isn't about admin. This is about everything that the rule tries to run on. Make sure that it only runs on something if it does not exist. This is just A Good Thing To Do, but it will also solve your problem. Quote Link to comment https://forums.phpfreaks.com/topic/309873-rewriterule-not-working-right/#findComment-1573575 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.