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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

#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]

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.