views:

25

answers:

3

hi,

i am new to a php site, only familiar with .net web forms sites.

i can't figure out how routing is working on this php site.

www.oursite.com/suggestions.php is to suggestions.php
www.oursite.com/suggestions also loads the php fine
www.oursite.com/suggestions/ loads the php, but no css is applied
www.oursite.com/suggestions/anything - anything that comes after the '/' is ignored and suggestions is loaded without css. so oursite.com/suggestions////// works, as does oursite.com/suggestions/2/2/2/2/whatever

i have searched but not found any good explanation on how this is working. can someone explain or provide a good resource?

thank you.

+2  A: 

This is most certainly done using Mod_Rewrite, an Apache extension. You'll probably find a file called .htaccess in the public root, in which these rewriting rules are defined.

Douwe Maan
A: 

DouweM has the right answer as far as the friendly urls are concerned.

As for the CSS, it is probably because you are using relative URLs in your link tags:

<link rel="stylesheet" href="site.css"/>

Change those to absolute URLs and it should solve that problem:

<link rel="stylesheet" href="/site.css"/>

The reason for this is that the browser makes the request for the CSS based on the directory it thinks it is in, even though your URL rewriting is changing that. So, if the url is http://mysite.com/suggestions/ and you are using relative urls, the browser will request the css as http://mysite.com/suggestions/site.css which of course doesn't exist.

Eric Petroelje
A: 
www.oursite.com/suggestions.php is to suggestions.php
www.oursite.com/suggestions also loads the php fine

You probably have a .htaccess file that first checks whether or not a file of that name exists, and if it does serves it, then, if it doesn't, tries to route it to a php script.

www.oursite.com/suggestions/ loads the php, but no css is applied

The / means your browser considers '/suggestions/' a directory. If suggestions.php outputs HTML that contains a relative <link> to a stylesheet, e.g. <link href="style.css">, your browser will request www.oursite.com/suggestions/style.css, rather than www.oursite.com/style.css as in the previous two cases.

www.oursite.com/suggestions/anything

Same as the previous case, your browser will request the wrong css file, since it considers '/suggestions/' a directory. (For a potential fix, take a look at Eric Petroelje's answer.)

As DouweM said, though, your best bet is to look directly at your .htaccess file and figure out what it does.

pinkgothic