Mod Rewrite Breaking embedded CSS, JS Links (PHP site)

Discussion in 'PHP' started by mark84, Jul 2, 2007.

  1. #1
    I used mod_rewrite to shift a url to hirarchy above it, which caused my CSS, Javascript and Image links to break. i.e. it cannot link to teh js, css file as the path changed with the rewrite.

    This is the current rewrite rule set. And the .htacccess is located in myportal directory.

    RewriteRule ^([^\s=&$\?][a-z0-9-]+(?:news-([0-9]{1,}))(?:\.s?html?))$ /myportal/php/news_details.php?news_id=$2 [NC,L]

    Is there a way to fix these embedded broken links using mod_rewrite or do i have to edit the php files manually ?
     
    mark84, Jul 2, 2007 IP
  2. Sinner20_ro

    Sinner20_ro Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hello,
    i had the same problem and i solved it pretty quickly using in the html head:
    <base href="http://www.mysite.com/"> ...
    That helps transforming your relative paths from "folder/style.css" into "http://www.mysite.com/folder/style.css"> ...
    I hope it helps ...
     
    Sinner20_ro, Jul 2, 2007 IP
  3. mark84

    mark84 Peon

    Messages:
    56
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks a lot mate :)
    You guys are amazing and very helpful.

    I was about re-adjust the hirarchy but was waiting for the reply.
    Guess it was well worth waiting for the reply. That one line
    sure saved a lot of work for me.
     
    mark84, Jul 2, 2007 IP