Apache RewriteEngine redirect messing up external CSS stylesheet referencing

Hello all,

Every page on my website is dynamically generated by a Perl script, pages.pl, including the homepage.

To accomplish this, I have an Apache RewriteEngine redirect script in the website's .htaccess file, like this:

RewriteEngine On
#redirect from domain to domains (in case url was mis-typed)
RewriteCond %{HTTP_HOST} =www\.domain\.com [NC]
RewriteRule .* http://www.domains.com%{REQUEST_URI} [L,R=301]
#and now to cgi-bin/pages.pl, unless it already cgi-bin/pages.pl
RewriteCond %{REQUEST_URI} !cgi-bin/rpages.pl
RewriteRule .* http://www.domains.com/cgi-bin/pages.pl [L,R=301]

(thanks to 'ravenpl')

That way, when a visitor surfs to www.domain.com or www.domains.com, instead of a static html homepage, they're automatically redirected to pages.pl which dynamically generates the homepage from a template.

That template contains the line

<LINK REL=StyleSheet HREF="../my_styles.css" TYPE="text/css">

If I remove the redirect script, and surf directly to http://www.domains.com/cgi-bin/pages.pl, the dynamically generated page calls its stylesheet just fine and it looks right.  

When I put the redirect script back into the .htaccess file and surf to www.domain.com or www.domains.com, the redirect occurs, the content of the page loads, but there is no styling. I've tried altering the relative path to the stylesheet in various ways - no good.

What's up?

Who is Participating?
ravenplConnect With a Mentor Commented:
#and now to cgi-bin/pages.pl, unless it already cgi-bin/pages.pl or *.css
RewriteCond %{REQUEST_URI} !cgi-bin/pages.pl
RewriteCond %{REQUEST_URI} !\.css$
RewriteRule .* http://www.domains.com/cgi-bin/pages.pl [L,R=301]
xfvgdrthbdtyvhgscvAuthor Commented:
Yep - that did it.  Thanks again.

So, looking at it, I infer that the stylesheet call in fact creates an http request that is subject to the conditions of the .htaccess file?  Interesting.
All Courses

From novice to tech pro — start learning today.