Problem CSS, Images, Links

Topics: Developer Forum, Project Management Forum, User Forum
Nov 11, 2008 at 9:01 PM
Hello, everyone.

I forgive me for my English, but I will try to explain my problem.
Tried here in the list of discussion but did not find any answers.

I have a problem when I use a rule as below:

RewriteRule ^ / shop / products / ([0-9]) (/ [a-zA-Z0-9_-])? (. Html)? $ /? Id = $ 1 [R]

The procedure normally occurs, but I have problem with the file path of my CSS, links and so on ... in the asp page.

In my file after entering the link:
http://localhost:83/shop/products/1234/testando.html

He does not display my CSS, images and modify my links in my default directory example:
In the source code of my default file have
<a href='test.html'> test </ a> that should go to
http://localhost:83/shop/teste.html
But using my rule it displays:
http://localhost:83/shop/products/1234/teste.html

How can I change this?
Coordinator
Nov 12, 2008 at 1:56 AM
The link to "test.html" and to your CSS and images... are RELATIVE.
Relative to the URL that the browser THINKS it is using.

The URL the browser is using is http://localhost:83/shop/products/1234/testando.html
You have rewritten the URL on the server side so that it points elsewhere.
(I don't know the result of the server-side rewrite, but I think it might be http://server/?id=1234  )

the page comes back to the browser and the relative links all refer to the containing URL space
http://localhost:83/shop/products/1234/

Therefore,
http://localhost:83/shop/products/1234/style.css
http://localhost:83/shop/products/1234/Image1.jpg

etc

If you want those URLs to result in
http://localhost:83/shop/style.css
http://localhost:83/shop/Image1.jpg

then you can use a separate rule to rewrite those URLs as well.

The alternative is to modify the page content so that it emits non-relative URLs, for example:
<a href="/shop/test.html">
or
<img src="/images/image1.jpg">

They have a leading slash, which makes them non-relative.




Nov 12, 2008 at 10:26 AM
So by what I understand there is the possibility of establishing a rule for that links, css and images are not affected by rewriting the url?
There is that possibility?
I tried to find the readme but as I said, my English is not very good.

Thank you very much.
Coordinator
Nov 12, 2008 at 1:15 PM
No.

There are two ways to avoid the problem you describe:
  1. Use absolute paths in your links for .css, .js, .jpg, etc
  2. use an additional rule to rewrite the relative links to those resources to the proper location.
I don't know how to explain it better than what I wrote above.

Maybe try reading this  thread: http://forums.iis.net/p/1152503/1882863.aspx
which explains the same concepts.

Nov 12, 2008 at 1:36 PM
2 - use an additional rule to rewrite the relative links to those resources to the proper location.
Okay, but that is my problem how to create this rule to rewrite the links on
I tried several ways of reading the readme and not succeeded.
Can you help me?
Coordinator
Dec 1, 2008 at 3:52 AM

I wrote:

Therefore,
http://localhost:83/shop/products/1234/style.css
http://localhost:83/shop/products/1234/Image1.jpg

etc

If you want those URLs to result in
http://localhost:83/shop/style.css
http://localhost:83/shop/Image1.jpg

then you can use a separate rule to rewrite those URLs as well.

For example, a rule that would accomplish this might be::

RewriteRule  /shop/products/([0-9](/[a-zA-Z0-9_-])?)/([^/]+\.(css|jpg))   /shop/$2  [L]

This rule says, for a request for a .css or .jpg, which includes /shop/products/xys6627278/style.css, rewrite to /shop/style.css

As always, test with the testdriver.

good luck!