Forum Moderators: phranque

Message Too Old, No Replies

.htaccess "fake url" but then i have problem with css

somehow confusing :P

         

mankgr

7:34 pm on May 20, 2009 (gmt 0)

10+ Year Member



Hi!

I would like some help regarding a .htaccess rule.
What i am trying to do:

Let's suppose that my site is:
http://www.example.com
And a url which shows something is:
http://www.example.com/show.php?id=12&name=cars

What i try to do is:

RewriteRule ^viewing/([0-9]+)(.+)/?$ ./show.php?id=$1&name=$2

So that the url be:
http://www.example.com/viewing/12-cars.html

The above works correctly,but the problem is that the page loads without .css,images etc
(It is set that the path to .css is eg ./template/mysitetheme/style.css)
The Same happens with links:
Eg the link to the homepage becomes: http://www.example.com/viewing/ instead of http://www.example.com (as the url-link to the homepage is:

<a href="./index.php"/>homepage</a>)

So i get an error that this page (http://www.example.com/viewing/) doesnt exist :(
How can i fix that using a rewrite rule (instead of course changing all links from eg ./index.php to http://www.example.com/index.php) ?

Thanks in advance!

[edited by: jdMorgan at 1:59 am (utc) on May 21, 2009]
[edit reason] example.com [/edit]

mankgr

8:08 pm on May 20, 2009 (gmt 0)

10+ Year Member



in fact what i want is to ignore the:
http://www.example.com/viewing/
and think that it is:
http://www.example.com/

[edited by: jdMorgan at 1:32 am (utc) on May 21, 2009]
[edit reason] example.com [/edit]

jdMorgan

1:22 am on May 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Don't change your page links. To correct this problem, change your image and css links from (for example), <img src="images/logo.gif"> to <img src="/images/logo.gif">

This is the most likely reason for your trouble. It is due to the fact that it is the client (e.g. browser) that resolves relative links. For page-relative links like <img src="images/logo.gif">, it does so based on the current page's 'directory' which is shown in the address bar.

So, if you are viewing a page at http://www.example.com/viewing/12-cars.html and that page includes an image link of <img src="images/logo.gif">, then the browser will remove "12-cars.html" and add "images.logo.gif", to get a canonical URL of "http://www.example.com/viewing/images/logo.gif". Since "/viewing" is not a 'real' directory, the image path is therefore wrong.

Adding the leading slash to the <img src> path causes the browser to remove all path information and add the specified URL-path to the domain's root, yielding the correct image URL of "http://www.example.com/images/logo.gif".

You can easily confirm this problem by looking at your server error log and access log files. The "Live HTTP Headers" add-on for Mozilla/Firefox browsers also comes in handy for debugging these problems. It's basic Webmaster kit.

Jim

mankgr

5:48 am on May 21, 2009 (gmt 0)

10+ Year Member



Hi,

Thanks for replying!
Yes,it works now!

Thanks. :)