Forum Moderators: phranque

Message Too Old, No Replies

htaccess changes local path to what?

         

merijnvw

10:39 am on Apr 25, 2010 (gmt 0)

10+ Year Member



Hi, I have a php page and without .htaccess(I use rewrite_mod) it implements some css and js files, that works. When using .htaccess, it won't implement them, I think it changes the standard path(I'm a beginner with .htaccess by the way). How can I change that back to how it should be? thanks.

g1smd

11:54 am on Apr 25, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Without some example.com type URLs, matching internal server path names, and some example code there's no way anyone could even begin to help you on this one.

merijnvw

3:10 pm on Apr 25, 2010 (gmt 0)

10+ Year Member



Well I do it like so: when people go to example.com/klaas, they get the page example.com/index.php?id=klaas. Index.php then includes three files: header.html, klaas.html, footer.html. That works, only the inclusion of the external js and css files(from header.html) doesn't work.
I can alternatively include those directly from inside index.php i think, but it is less clean. And I would like to know why this happens.

merijnvw

8:32 pm on Apr 25, 2010 (gmt 0)

10+ Year Member



Of course! I was being dumb. I used .htacces to change all example.com/klaas requests to example.com/index.php?id=klaas, but when an external script is included from the 'scripts' folder, that folder is of course also rewritten.
I'll now try to find out how to make an exclusion for certain folders.

merijnvw

8:42 pm on Apr 25, 2010 (gmt 0)

10+ Year Member



got it. excluded the folders with:
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
by placing the above before the RewriteRule

g1smd

9:50 pm on Apr 25, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



One other tip.

Use
src="[b]/[/b]the-path/to-the-file.ext"
to link to resources such as images, and CSS and JS files for a trouble free life (note the leading slash).

It is the browser that resolves what URL to ask for, based on the current folder level of the URL of the currently requested HTML page.

jdMorgan

12:57 am on Apr 26, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You've chosen to use a very inefficient method, there...

Be aware that every HTTP request to your server now generates anywhere from one to four extra filesystem reads to check for 'file or directory exists." It would be a very good idea to exclude images, css, and JS files (at a minimum) from these 'exists' checks, as well as excluding 'index.php' itself...

RewriteCond $1 !^index\.php$
RewriteCond $1 !\.(gif|jpe?g|png|ico|css|js)$
RewriteCond $1 !^admin/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php?id=$1 [L]

This example code also excludes the entire "/admin/" directory-path, just as an example.

Jim