Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Feb 2009
    Location
    Worcester
    Posts
    172
    Thanks
    13
    Thanked 6 Times in 6 Posts

    PHP Rewrite tweak - can anyone help?

    Hi guys!

    I started a tread about this here, but it went quiet so thought I'd start a new one, plus I've got a bit further so thought it deserved a new thread. Mods feel free to remove if this is wrong.

    So here's what I'm trying to do, I have a rule that redirects mydomain.com/joebloggs to mydomain.com/public/mypage.php?id=joebloggs and this works fine, but when I view the page all my links are broken, ie, css, js, images etc.

    Here's what I'm using for this:

    Code:
    RewriteEngine on
    RewriteRule ^([^/]*)$ public/mypage.php?id=$1 [L]
    So thought I'd try this:

    Code:
    RewriteEngine on
    RewriteRule ^public/([^/]*)$ public/mypage.php?id=$1 [L]
    But that didn't work! As you can see I have no idea what I'm doing with this, but I'm assuming it's because my page is in my public folder, and any incoming request for mypage.php in public folder is redirected to mydomain.com, and that's one level up, so the links are breaking. I've tried fiddling with the code to make it go up one level, so the request of mydomain.com/public/mypage.php?id=joebloggs goes to mydomain.com/public/joebloggs.

    Any ideas anyone?

  • #2
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,300
    Thanks
    4
    Thanked 203 Times in 200 Posts
    This is probably more related to how you are referencing your styles, JS and images on the page rather than how the rewrite is being done.
    Dave .... HostMonster for all of your hosting needs

  • #3
    Regular Coder
    Join Date
    Feb 2009
    Location
    Worcester
    Posts
    172
    Thanks
    13
    Thanked 6 Times in 6 Posts
    Quote Originally Posted by djm0219 View Post
    This is probably more related to how you are referencing your styles, JS and images on the page rather than how the rewrite is being done.
    Thanks for the reply.

    I'm not sure, as I explained when I go to mydoman.com/joebloggs I get successfully redirected to mydomain.com/public/mypage.php?id=joebloggs, so isn't the server thinking I'm up one level as I should be in mydomain.com/public/joebloggs (real url is mydomain.com/public/mypage.php?id=joebloggs)

    Or do you think I should use absolute paths for my links as I'm using relative ones at the moment?

    Thanks for taking the time to reply though

  • #4
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,300
    Thanks
    4
    Thanked 203 Times in 200 Posts
    Exactly how are you referencing images etc in your pages (show us an example please)?
    Dave .... HostMonster for all of your hosting needs

  • #5
    Regular Coder
    Join Date
    Feb 2009
    Location
    Worcester
    Posts
    172
    Thanks
    13
    Thanked 6 Times in 6 Posts
    Quote Originally Posted by djm0219 View Post
    Exactly how are you referencing images etc in your pages (show us an example please)?
    Sure. Here goes:

    <link rel="stylesheet" href="css/layout.css" type="text/css" media="all" />

    <script type="text/javascript" src="js/tools/jQuery.js"></script>

    <img src="imgs/img.png" />

    So they're all relative to the doc. This is why I'm thinking it's losing them when the rewrite looks like it goes up one level from public (public folder is where all the linked folders are like js, img, css etc)

  • #6
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,853
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Sure. Here goes:

    <link rel="stylesheet" href="css/layout.css" type="text/css" media="all" />

    <script type="text/javascript" src="js/tools/jQuery.js"></script>

    <img src="imgs/img.png" />
    Change them all to
    Code:
    Sure. Here goes:
    
    <link rel="stylesheet" href="/css/layout.css" type="text/css" media="all" />
    
    <script type="text/javascript" src="/js/tools/jQuery.js"></script>
    
    <img src="/imgs/img.png" />
    See http://www.codingforums.com/showthre...167#post784167 to know more.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #7
    Regular Coder
    Join Date
    Feb 2009
    Location
    Worcester
    Posts
    172
    Thanks
    13
    Thanked 6 Times in 6 Posts
    Quote Originally Posted by abduraooft View Post
    Change them all to
    Code:
    Sure. Here goes:
    
    <link rel="stylesheet" href="/css/layout.css" type="text/css" media="all" />
    
    <script type="text/javascript" src="/js/tools/jQuery.js"></script>
    
    <img src="/imgs/img.png" />
    See http://www.codingforums.com/showthre...167#post784167 to know more.
    Thanks for the pointer, and interesting other post too

    Unfortunatly this didn't work, but I did try adding the public/ to all the links an voila, all working. So it is a problem with the rewrite as it think it's going up one level.

    So do you happen to know how I could modify

    Code:
    RewriteRule ^([^/]*)$ public/mypage.php?id=$1 [L]
    to include the public/ in there?

    I've tried a few variations but cant seem to get it to work.

    Here's something like what I think it would look like:

    Code:
    RewriteRule ^public/([^/]*)$ public/mypage.php?id=$1 [L]
    OR
    RewriteRule public/^([^/]*)$ public/mypage.php?id=$1 [L]
    OR
    RewriteRule ^([^public/]*)$ public/mypage.php?id=$1 [L]
    But I don't know anything about rewrites, hence why I'm just stabbing in the dark hoping something will work! lol

    Thanks for your time
    Last edited by loki421; 11-01-2010 at 07:02 PM. Reason: Can't spell! :p


  •  

    Posting Permissions

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