jon
jon

Reputation: 1581

htaccess rewrite to create friendly urls

The following rule works, but it changes the URL in the address bar, which is not intended.

RewriteRule ^network/(.*)$ http://www.example.com/network.php?networkUrl=$1 [L]

The following rule redirects, the URL stays the same, but all the images, includes in the network.php file become referenced incorrectly...

RewriteRule ^network/(.*)$ network.php?networkUrl=$1 [L]

Is there a way to make this work?

Upvotes: 0

Views: 130

Answers (2)

ecchymose
ecchymose

Reputation: 673

Setting a base href HTML tag in your page could help too:

<base href="http://www.domain.com/" />

then all your relative images, stylesheets or javascript files will be relative to this base href.

http://www.w3.org/wiki/HTML/Elements/base

Upvotes: 0

Fabio
Fabio

Reputation: 19216

This is because your browser interprets paths as relative.

To solve this reference your images and CSS with absolute paths, i.e. <img href="image.jpg" /> becomes <img href="/image.jpg" />

Same applies for css so

<link href="stylesheets/foo.css" media="print" rel="stylesheet" type="text/css"/> 

becomes

<link href="/stylesheets/foo.css" media="print" rel="stylesheet" type="text/css"/> 

In this way all resources links works as expected when referenced from any depth as /foo/bar/baz/script.php and so on.

Upvotes: 5

Related Questions