Forum Moderators: phranque

Message Too Old, No Replies

URL rewriting causing page layout errors

         

hybridization

10:28 pm on Aug 20, 2008 (gmt 0)

10+ Year Member



Hello,

New here and would love some help.

I am trying to rewrite a url, and I got it to work, but it looks like all the CSS formatting disappers when I do so.

This is what I have in my .htaccess file:

RewriteEngine on
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ file.php?val1=$1&val2=$2 [L]

which outputs this url

www.mysite.com/value1/value2

When I navigate to that page, all the formatting is gone. Do I need to add or remove something from the .htaccess?

Thanks a lot.

-Chris

ag_47

10:50 pm on Aug 20, 2008 (gmt 0)

10+ Year Member



file.php is linking to a .css file relative to the directory it's in, which ISNT /value1/value2/.
In other words it's looking for say "index.css" somewhere in /value1/value2/.

In file.php, add a / (slash) to the css include:

<link type="text/css" href="/styles/index.css" rel="stylesheet" />

Assuming www.site.com/styles/index.css

hybridization

1:08 am on Aug 21, 2008 (gmt 0)

10+ Year Member



my style sheet is in my root folder, along with file.php.

value1 and value two are not directories, they are variables that are dynamically generated on the output page.

i.e. www.mysite.com/file.php?val1=free-phone&val2=chicago

becomes

www.mysite.com/free-phone/chicago

and "free phone" and "chicago" appear on the output page.

ag_47

1:26 am on Aug 21, 2008 (gmt 0)

10+ Year Member



Exactly. That's why the stylesheet is not found, because these folder don't exist.
Just add a / in front of the stylesheet link (no other changes), that's all you need.

hybridization

5:09 am on Aug 21, 2008 (gmt 0)

10+ Year Member



Gotcha.

Thanks a lot for that, it worked!