help with mod_rewrite problem

Discussion in 'Apache' started by southhill, Jun 16, 2006.

  1. #1
    I have a site with the following structure:

    domain.com
    -- a.php
    -- /data
    ---- b.php
    ---- c.css
    ---- /articles
    ------ d.txt

    a.php contains one line:
    include ('data/b.php');

    a.php takes a querystring in the format ?article=d.txt and b.php gets the content of domain.com/data/articles/d.txt and displays it.

    b.php also contains this line:
    <link href="data/c.css" rel="stylesheet" type="text/css" />

    what I'm trying to do is use mod_rewrite so that instead of using
    http://domain.com/a.php?article=d.txt

    a user would type
    http://domain.com/articles/d.php

    I've written a rule that works to a degree. It displays the article, but the problem is that the css file is not applied.
    What am I missing?

    RewriteEngine on
    RewriteRule ^articles/([^/.]+)\.php$ a.php?article=$1\.txt [L]


    thanks in advance for any help you can give me. I'm just learning about mod_rewrite and I'm sure it's something simple.
     
    southhill, Jun 16, 2006 IP
  2. LinkBliss

    LinkBliss Peon

    Messages:
    697
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I've done a lot of mod_rewrite but with httpd.ini files which I don't think are compatible. My bit of advice would be to break it down and try it bit by bit on the tiniest morsel until you have it.
    Good luck.
    Eric
     
    LinkBliss, Jun 16, 2006 IP
  3. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #3
    You have to change the CSS code in the HTML so it's as if the mod_rewrite URL was the actual URL.

    CSS and mod_rewrite hate each other!!!!
     
    Nintendo, Jun 16, 2006 IP
  4. southhill

    southhill Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for your reply.

    I didn't really understand your reply, but is editing the HTML the only solution? I oversimplified the problem, and there are actually many files affected, not just one. I was hoping that I could get this to work by only modifying .htaccess

    Would it help to put another copy of the css file in another directory?

    If not, can you tell me what code needs to be changed?
     
    southhill, Jun 16, 2006 IP
  5. Nintendo

    Nintendo ♬ King of da Wackos ♬

    Messages:
    12,890
    Likes Received:
    1,064
    Best Answers:
    0
    Trophy Points:
    430
    #5
    All .htaccess does is makes fake URLs work. Changing the URLs drives CSS insane. Post the html of the code where you get the file and an example of the file URL, and the URL of the css file and I can try to get you the code. (I'm a CSS n00bie.)
     
    Nintendo, Jun 17, 2006 IP
  6. southhill

    southhill Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks. I was able to figure it out myself.
     
    southhill, Jun 17, 2006 IP