views:

376

answers:

2

After looking at 4-5 different ways to get simple clean URLs for static files, we found one that was simple and easy to implement/maintain over multiple folder and files.

One problem, it wont load the js/css/images from that folder it is looking at.

Here is the rule - it loads the html ok, but not the images, etc which are in the /images folder of /hello

RewriteRule ^hello/$ /hello/index.html [L]

RewriteRule ^company/$ /hello/company.html [L]

Any suggestions, folks?

A: 

Your problem is that you are rewriting the /company to /hello/company.html, so the browser thinks you have opened http://yoursite.com/company If the image is loaded with a relative url, it then tries to load the picture with an URL http://yoursite.com/company/images/pic.jpg So you have to rewrite everything in the non-existant /company/images folder to /hello/images folder

RewriteRule ^company/images/(.+) /hello/images/$1 [L]
naivists
The URL path `/hello/` is always not equal to `.*\.js`.
Gumbo
@Gumbo thanks for your comment, finally I understood the question :-)
naivists
@Gumbo/naivists - I guess I am not trying that option :)
Sukh
naivists - thank you but that did not work yet. Do you propose an alternate way to get clean URLs with folders and static HTMLs without facing the image linking problem?
Sukh
@Sukh, my code was a bit wrong, changed it (I had a / in front of the match, but had to have a ^ there). Check your Apache logfiles to see where it actually tries to find the image and what happens. You will have to set the "RewriteLog" directive in apache config, will look simething like RewriteLog "/usr/local/var/apache/logs/rewrite.log"
naivists
@naivists - that worked, but the /css folder with one file isn't working with that same line. I tried both of these:RewriteRule ^company/css/ /hello/css/$1 [L]RewriteRule ^company/css/(.+) /hello/css/$1 [L]
Sukh
@Sukh, I think you need `RewriteRule ^company/css/(.+) /hello/css/$1 [L]` here
naivists
@naivists - no luck. Offline - are you interested in doing a paid consultation with remote access?
Sukh
Could you post contents of the whole .htaccess you have right now?
naivists
A: 

Or move your static assets to a different host/subdomain.

Azeem.Butt
That makes sense when production websites are deployed. When you are writing quick, mocks, it is just a whole lot faster to just do /images/... and link images in there.
Sukh
Doesn't seem like it's saving you any time right now.
Azeem.Butt