...

View Full Version : PHP Rewrite tweak - can anyone help?



loki421
11-01-2010, 02:29 PM
Hi guys!

I started a tread about this here (http://www.codingforums.com/showthread.php?p=1009477#post1009477), 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:



RewriteEngine on
RewriteRule ^([^/]*)$ public/mypage.php?id=$1 [L]


So thought I'd try this:



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? :)

djm0219
11-01-2010, 02:40 PM
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.

loki421
11-01-2010, 04:01 PM
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 :)

djm0219
11-01-2010, 04:47 PM
Exactly how are you referencing images etc in your pages (show us an example please)?

loki421
11-01-2010, 06:13 PM
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)

abduraooft
11-01-2010, 06:31 PM
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

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/showthread.php?p=784167#post784167 to know more.

loki421
11-01-2010, 08:00 PM
Change them all to

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/showthread.php?p=784167#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



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:



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 :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum