SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    redirection in apache going into endless loops

    Hi

    I have RedHat 9 with apache installed my redirection for the website works fine. Now I have installed RHEL 4 with apache with the same httpd.conf config
    and when i enter the username and password it goes into endless loops

    this is the RedirectCode


    RewriteEngine on


    RewriteRule ^/$ /en/index.php [R]


    # First change /en or /ar into /en/ and /ar/

    #RewriteRule ^/(en|ar)$ /$1/ [R]


    # Next add the index.php to URLs ending in /

    RewriteRule ^(.*)/$ $1/index.php [R]

    RewriteRule (.*)/member/cgi-bin/(.*) $1/cgi-bin/member/$2

    RewriteRule ^/(en|ar)/cgi-bin/(.*)$ /cgi-bin/$2/$1 [T=application/x-httpd-cgi]


    RewriteCond %{DOCUMENT_ROOT}/$2.$1.$3 -s

    RewriteRule ^/(en|ar)/(.*)\.([a-z0-9]*)$ /$2.$1.$3


    RewriteCond %{DOCUMENT_ROOT}/$2.$3 -s

    RewriteRule ^/(en|ar)/(.*)\.([a-z0-9]*)$ /$2.$3


    RewriteCond %{DOCUMENT_ROOT}/$2/index.$1.php3 -s
    RewriteRule ^/(en|ar)/(.*)/index.php$ /$2/index.$1.php


    RewriteCond %{DOCUMENT_ROOT}/$2/index.php3 -s

    RewriteRule ^/(en|ar)/(.*)/index.php$ /$2/index.php


    ##RewriteRule ^/(en|ar)/(.*)/index.php$ /$2
    /

    ##RewriteMap usage-map prg:/usr/local/var/kse/cgi-bin/member/usage

    RewriteLog /etc/httpd/logs/rewrite_log
    RewriteLogLevel 0

    LogLevel debug

    HostNameLookups off

    </VirtualHost>


  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,645
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    yesrkay,

    Okay, I don't know whether to claim that I'm a novice or that your regex is faulty but I've NEVER seen $n in regex before (not to mention other oddities). Since I deal with mod_rewrite redirections and the best place for those is in an .htaccess file, "compiling" them in to Apache on start with httpd.conf seems the hard way to do things.

    While pippo or Mike may understand what you're trying to do, I don't. Would you please explain? I guess, the comments SHOULD be self explanatory (they're not logical to me -- my problem or the late hour) but what username and password are talking about that causes the loop?

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    DK

    The website is live.q8stocks.com.kw.
    U have an english and arabic interface using redirection
    The user has to login in this screen

    At present the configuration is running on RH9 ,but now we are going for an upgradation to RHEL 4.

    This redirect code works fine in RH9 allowing the user to login

    but in RHEL4 the same redirect code goes into endless loops

    This code was written by one of my colleague who has left the company long time back and I am a novice in redirection.

  4. #4
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn
    yesrkay,
    Since I deal with mod_rewrite redirections and the best place for those is in an .htaccess file, "compiling" them in to Apache on start with httpd.conf seems the hard way to do things.
    Really the best place for your rules is within the httpd.conf file instead of having to load a seperate .htaccess file each page load I remember reading pippo expain this a while ago.l

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,645
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    yesrkay,

    Hmmm, very confusing!

    May I suggest that the redirections be removed from the httpd.conf until they can be corrected - put these rules in the .htaccess file in your root directory so you can change them without having to restart Apache.
    Code:
    RewriteEngine on
    # redirect to english as default
    RewriteRule ^$ /en/index.php [R]
    
    # First change /en or /ar into /en/ and /ar/
    #RewriteRule ^/(en|ar)$ /$1/ [R]
    
    # Next add the index.php to URLs ending in /
    # This SHOULD be handled in the httpd.conf as
    # DirectoryIndex index.html index.html.var index.php index.php3 index.phtml
    RewriteRule ^(.*)/$ $1/index.php [R]
    
    # handle cgi-bin calls
    RewriteRule (.*)/member/cgi-bin/(.*) $1/cgi-bin/member/$2
    RewriteRule ^(en|ar)/cgi-bin/(.*)$ /cgi-bin/$2/$1 [T=application/x-httpd-cgi]
    
    # UNDEFINED VARIABLES - commented out
    # RewriteCond %{DOCUMENT_ROOT}/$2.$1.$3 -s
    
    RewriteRule ^/(en|ar)/(.*)\.([a-z0-9]*)$ /$2.$1.$3
    
    # may use variables from prior rule
    RewriteCond %{DOCUMENT_ROOT}/$2.$3 -s
    
    # * should probably be + to require at least one letter/digit
    RewriteRule ^(en|ar)/(.*)\.([a-z0-9]*)$ /$2.$3
    
    # may use variables from prior rule - php3??? That's got to be an OLD file!
    RewriteCond %{DOCUMENT_ROOT}/$2/index.$1.php3 -s
    RewriteRule ^(en|ar)/(.*)/index.php$ /$2/index.$1.php
    
    #ditto
    RewriteCond %{DOCUMENT_ROOT}/$2/index.php3 -s
    
    RewriteRule ^/(en|ar)/(.*)/index.php$ /$2/index.php
    I've removed leading slashes from regex (not in {REQUEST_URI} and commented out the one rule that looked like it could not use a $3 variable from a prior rule.

    May I respectfully suggest that you do through the site and determine what redirects are actually required so the need for them can be specified (and accurate code written)?

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  6. #6
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    DK
    The solution u suggested did not work. I still get endless loops

  7. #7
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,645
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    yesrkay,
    Quote Originally Posted by dklynn
    May I respectfully suggest that you do through the site and determine what redirects are actually required so the need for them can be specified (and accurate code written)?
    Until you know what the rewrite rules are supposed to do - and what is requiring the username/password 'cause it's not in the code you've shown - it's impossible to offer more useful suggestions.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  8. #8
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    DK

    The site has two interface arabic and english
    the default redirection goes to the english page

    The user logs in a perl scripts runs from cgi-bin authenticating the user and returns back to the orignal page showing the user name in place of the login screen.

    With RHEL 4 the user is able to login but the process goes into loop

  9. #9
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,645
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    yesrkay,

    Thank you, the "interfaces" explains the two directories.

    Your further description suggests that either your PERL script is not setting the SESSION variables correctly, your SESSION storage on the site has changed without the settings being updated (httpd.conf under SESSIONS) or that your original script isn't properly handling the SESSION information set by PERL.

    The most likely is the second option. If you're using a db to store SESSION information (for verification of user access), it's likely that the db location's been changed and that needs to be updated in the PERL script AND the original script. The original script should also be looking for an HTTP_REFERER in addition to the SESSION info so that should also be checked.

    I hope these suggestions point you in the right direction.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  10. #10
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    DK

    The problem was not with the redirection but one of the perl files. There was some problem with the copying and the files was trying to contact the database
    server and going in to an infinite loop

    neways thanks for your help and now have learnt a lot about redirection

  11. #11
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,645
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    yesrkay,

    Well, we accomplished something, then, didn't we! Horray!



    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •