Files being mod_rewritten to incorrect url

Discussion in 'Apache' started by egdcltd, Apr 28, 2007.

  1. #1
    I have a script that uses mod_rewrite to alter all the urls. However, the script is based in a sub-directory, rather than root, and all the urls are being rewritten to root, which makes them incorrect.

    The onlt thing I can think of that could be doing this for all files is the .htaccess file (below). Is this the case and how would I alter it if so?

    RewriteEngine On 
    #turn on the Rewrite engine, if it's not already active 
    
    #set the base directory to / 
    RewriteBase /
    
    # now the rewriting rules 
    RewriteRule ^games/ games.php [L]
    
    # now the rewriting rules 
    RewriteRule ^game/ game.php [L]
    Code (markup):

     
    egdcltd, Apr 28, 2007 IP
  2. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Change
    #set the base directory to / 
    RewriteBase /
    Code (markup):
    to
    #set the base directory to /subdir/
    RewriteBase /subdir/
    Code (markup):
    (where subdir is the name of your subdirectory, obviously)
     
    rodney88, Apr 28, 2007 IP
  3. egdcltd

    egdcltd Peon

    Messages:
    691
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hmm, I tried that and it didn't work. Could the fact that it's on a subdomain too be causing a problem?
     
    egdcltd, Apr 28, 2007 IP
  4. Jim_

    Jim_ Peon

    Messages:
    72
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Try removing the RewriteBase line altogether.
     
    Jim_, Apr 28, 2007 IP
  5. egdcltd

    egdcltd Peon

    Messages:
    691
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #5
    That didn't fix it either. I can't see what else would affect all the files in the directory, except the .htaccess file.
     
    egdcltd, Apr 28, 2007 IP
  6. Jim_

    Jim_ Peon

    Messages:
    72
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    RewriteRule ^games/ subdir/games.php [L]
    RewriteRule ^game/ subdir/game.php [L]

    How about that?
     
    Jim_, Apr 28, 2007 IP
  7. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #7
    I'm not sure because you have not post your origin and destiny urls, but maybe you need something like this:

    RewriteRule ^gam(e|es)\/(.+)\.html /games.php?$2
     
    ajsa52, Apr 28, 2007 IP
  8. Faltzer

    Faltzer Peon

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Hmm, out of curiosity, but why do you have an ending slash if the rewriterule automatically does the slash for you?
     
    Faltzer, Apr 28, 2007 IP
  9. egdcltd

    egdcltd Peon

    Messages:
    691
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #9
    All the files are supposed to end up in games.directorygold.com/GameZone however, they're being written into games.directorygold.com which means all links are broken. I can fix it be editing every file that has a url in it, but I thought it would be something global.

    I have no idea regarding the trailing slash, that's how it came with the script and I know almost nothing abut .htaccess.

    Going to give the other ideas a try.
     
    egdcltd, Apr 29, 2007 IP
  10. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Do you have the correct href location for your links (i.e. the status bar shows games.directorygold.com/GameZone when you hover over the link)?

    If not, it's not actually a problem with mod_rewrite - it'd be a problem with your script. The best solution would be to update the script but you could also use mod_rewrite to transparently add in that missing directory. Jim's suggestion should do this for you.

    If the links are correct, then the problem is to do with your rewrites. Altering the rewrite base should work, or add in the extra subdirectory to both the pattern and destination.

    mod_rewrite can only intercept requests and rewrite to a different location. It can't alter the output of your scripts to make URLs in the proper format.
     
    rodney88, Apr 29, 2007 IP
  11. egdcltd

    egdcltd Peon

    Messages:
    691
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #11
    No, the links are incorrect too. What else would globally affect all links other than .htaccess?
     
    egdcltd, Apr 29, 2007 IP