Aman Singh
Aman Singh

Reputation: 753

url rewriting is not working for relative paths

I am a newbie for rewriting url, I have rewritten my url, but it is causing problem for all the relative paths used in the page like

<link href="style/style.css" rel="stylesheet">
<link href="images/icon.png" type="images/ico" rel="icon" />
<img src="images/test.png" id="test">

Even i have applied the following rewrite rule for them, but still i find 404 error in firebug console (first one is working but second is not working for relatvie)

RewriteEngine On
RewriteRule ^raipur/([A-Za-z0-9-]+)/([0-9]+)$ /viewRestaurant.php?raipur=$1&id=$2
RewriteRule ^raipur/([A-Za-z0-9-]+)/([A-za-z]+)/ /$2/

my console screenshot this is console screenshot

I had even debugged my rewrite rule into htaccess tester and its working there as required

Upvotes: 3

Views: 1233

Answers (1)

Jon Lin
Jon Lin

Reputation: 143906

You links are all relative links. "images/icon.png" instead of "/images/icon.png". Because your url changed its URL base from:

/viewRestuarant.php
Base: /

to

/raipur/something/1234
Base: /raipur/something/

When the browser sees a link like: images/icon.png it needs to prepend a base URL to it in order to know where the resource is located. By default it uses the host and base based off of the URL that it sees in the location bar. Since that's obviously not where any of these resources are, you need to either make your links into absolute URL's like: /images/icon.png or http://example.com/images/icon.png or add an explicit relative URL base into the header of your pages (between the <head> </head> tags):

<base href="/" />

Upvotes: 6

Related Questions