mod_rewrite for index file to root redirect

Discussion in 'PHP' started by web_junkie, Jun 7, 2008.

  1. #1
    Hi, I do not know if some one can help me with this,I have this script on my . htaccsess flie to redirec all index.php requests to the root, www.mysite.com :

    RewriteCond %{THE_REQUEST} ^.*/index.php
    RewriteRule ^(.*)index.php$ http://www.peruvianfur.com/$1 [R=301,L]

    which seems to work fine, however, when I tried to enter the administration panel of my website, i am not able to log in, and the only way to log in is to disable the script. i think is because there is and index file also in this folder, do you know how can it be modify so it does not affect other parts of the site.

    Thanks
     
    web_junkie, Jun 7, 2008 IP
  2. Bryce

    Bryce Peon

    Messages:
    1,235
    Likes Received:
    93
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The problem is you're doing "greedy matching" in the first part of the RewriteRule and the anchor ^(.*)index.php will redirect any index.php *in any folder*. This is why when you try you access your admin panel, you are redirected.

    if you only want to redirect requests to www.mysite.com/index.php to www.mysite.com, all you have to do is remove the (.*)
     
    Bryce, Jun 7, 2008 IP