After url rewrite, links in page contnet becoming broken

Hi folks,

my property rental site has properties list for rent and each property detail page having a url like below

http://www.example.com/view-property.php?pid=116

now i have rewritten this url as follows

rewriteRule ^property/([0-9]+)/?$ view-property.php?pid=$1 [L]

now problem is when i execte a rewritten url, the linkes in that page shows broken. for example

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

is broken, it shows

The requested URL /property/style.css was not found on this server.

You should probably rewrite your <link> to be more general. Is your style.css on the root folder?

Make it something like “href=”/style.css" to where it always has a starting folder to go to. The slash (/) in the beginning makes it look to the root folder and start there.

All of your pages should be doing something like this. All your file calls.

Awesome.

Make it something like “href=”/style.css" to where it always has a starting folder to go to.

yes, i have a bad practice that i do not refer to urls from the root /. i just put a slash infront of style.css and it works !!!

Thanks a lot Ryan.

afridy,

Your problem is that you’re redirecting to a level in your directory structure different than the request … AND you’ve made matters worse (if possible) by giving visitors the option to make the request look another level deeper with the optional trailing /.

IMHO, I’d:

  1. Delete the /? (optional trailing /) before the $ (end anchor)
  2. Use relative links which are based on the property/ subdirectory. Yes, I know it doesn’t exist but Apache doesn’t!

OR, as RR suggested,

  • Use (internal) absolute links for all links within the view-property script. I consider this the weaker of the two approaches but it would resolve your current problem…

Regards,

DK

Thanks dklynn for the valuable advise. sure ill check it.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.