Forum Moderators: phranque

Message Too Old, No Replies

Css always recheable

with mod_rewrite ;-)

         

Dapuzz

4:53 pm on Feb 5, 2005 (gmt 0)

10+ Year Member



Hi
i whould like to know how to redirect all request to a *.css file to my /css_folder/*.css
I paste here what i have write (and copied from ohterh sites)

RewriteEngine on
RewriteCond %{REQUEST_FILENAME}!/css_folder/style.css #to not loop
RewriteCond %{REQUEST_FILENAME}!-f #if doesn't exist
RewriteRule (.*).css /css_folder/$1.css #redirect

Can someone comment this solution?
Many thanks and forget my english.

jdMorgan

8:11 pm on Feb 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




RewriteEngine on
# not to loop
RewriteCond %{REQUEST_FILENAME} !/css_folder/
#if doesn't exist
RewriteCond %{REQUEST_FILENAME} !-f
# redirect
RewriteRule ([^/.]+)\.css$ /css_folder/$1.css [L]

This code will drop any folder path information, and keep only the name of the css file. If that's not what you want, then try

RewriteRule ^(.+)\.css$ /css_folder/$1.css [L]

I'll bet you speak my language better than I speak yours! :)

Jim

Dapuzz

11:43 am on Feb 6, 2005 (gmt 0)

10+ Year Member



yes, all is working fine with the first method. Thanks a lot.

Ps: I'm italian... :)

madmatt69

4:02 am on Feb 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Out of curiosity - What's the benefit of doing this?

Caterham

2:10 pm on Feb 7, 2005 (gmt 0)

10+ Year Member



What's the benefit of doing this?

If you use "virtual dirs", such as [example.com...] and reference images/styles relative (src="css_folder/style.css"), the browser would request [example.com...]

This broken path is being rewritten to the exsisting path [example.com...]

Bob

bird

3:01 pm on Feb 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As the first rule use this:

RewriteRule ^css_folder/.* - [L]

That ends all mod_rewrite processing for the directory in question (the [L] flag), but does nothing else (the - rule).
After that, the rule doing your actual internal redirect can be very simple, and doesn't need any further tests:

RewriteRule (.*).css /css_folder/$1.css [L]

Dapuzz

10:21 pm on Feb 7, 2005 (gmt 0)

10+ Year Member



RewriteRule (.*).css /css_folder/$1.css [L]

is it a mistake? Do i have to escape the "." like above?
RewriteRule (.*)\.css /css_folder/$1.css [L]

strategy

4:13 pm on Feb 28, 2005 (gmt 0)

10+ Year Member



css rule it works fine to me,
but i want to do same for all images (jpg, jpeg, gif, png, bmp) from /images/ and all functions ( .php and .js ) from /functions/

this is not working for me,

# not to loop
RewriteCond %{REQUEST_FILENAME}!/images/
#if doesn't exist
RewriteCond %{REQUEST_FILENAME}!-f
# redirect
rewriterule ([^/.]+)\.gif$ /images/$1.gif [L]

for exemple ..

strategy

7:29 pm on Feb 28, 2005 (gmt 0)

10+ Year Member



i solved the problem ..

there is some rule to not diplay file content of one directory where index.html/.php is missing?

Caterham

8:23 pm on Feb 28, 2005 (gmt 0)

10+ Year Member



there is some rule to not diplay file content of one directory where index.html/.php is missing?
Try in your .htaccess

Options -Indexes

If you get a 500 internal server error, you're not allowed to set this value in .htaccess files.

strategy

9:55 pm on Feb 28, 2005 (gmt 0)

10+ Year Member



thanks .. it works smooth ;)

Dapuzz

10:05 pm on Feb 28, 2005 (gmt 0)

10+ Year Member



Options -Indexes

isn't it a default options in a hosting webspace?