Jump to content
mikejv

RewriteRule not working right

Recommended Posts

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!
 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.