Forum Moderators: phranque

Message Too Old, No Replies

Mod Rewrite Question

         

kb1100

12:31 am on Mar 12, 2008 (gmt 0)

10+ Year Member



I have a pre-existing rewrite that I am trying to add on to, as I have added more dynamic elements to the page. The first one still works, but when the page for the second part gets loaded it only shows the links that are on the page. No style, no background colors, just links.

Example url: http://www.example.com/user.php?USERNAME&item=ITEMNAME
Currently works: http://www.example.com/USERNAME
Doesn't quite work: http://www.example.com/USERNAME/ITEMNAME

Here are the rewrites that I am using:
RewriteRule ^([a-z0-9_\-]+)$ /user.php?user=$1 [NC,L]
RewriteRule ^([a-z0-9_\-]+)/([a-z0-9_\-]+)$ /user.php?user=$1&item=$2 [NC,L]
RewriteRule ^([a-z0-9_\-]+)/$ http://www.example.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /user\.php\?user=([^&]+)&item=([^&]+)\ HTTP/
RewriteRule ^user\.php$ http://www.example.com/%1/album/%2? [R=301,L]

I am really not sure why this is resulting in the page not fully displaying. If someone knows I would appreciate the help!

jdMorgan

1:39 am on Mar 12, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It is likely happening because you've used relative links on that page. Since it is the browser which resolves relative links in accordance with the URL in its address bar, and since that page is now one 'virtual' directory-level deeper, the links to css, images, and external JS files will no longer be valid.

You have a couple of choices: One is to use server-relative or canonical URLs to reference those included objects. The other is to detect URL requests for images, css, JS, and any other objects which are to be shared by all virtual directory levels, and rewrite them to remove the extra directory levels, or point them all to a common directory path.

Page-relative link: <img src="images/logo.gif">
Page-relative link: <img src="../images/logo.gif">
Server-relative link: <img src="/images/logo.gif">
Canonical link: <img src="http://www.example.com/images/logo.gif>"

Jim

g1smd

11:17 am on Mar 12, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



To be clear, the first two formats cause problems, and the last two formats solve those problems.

kb1100

3:10 pm on Mar 12, 2008 (gmt 0)

10+ Year Member



That fixed it thanks!