Search code examples
.htaccessmod-rewritestylesheet

htaccess mod rewrite rule causes stylesheet to not load


In my htaccess I put a few rewrite rules to change my ugly dynamic urls, into clean, static impersonators:

mysite.com?content=content&content_att=content_att
mysite.com/content/content_att

in .htaccess

RewriteRule ^([A-Za-z0-9]+)/([^/]+)/?$ ?a=b&content=$1&content_att=$2 [L,QSA]
RewriteRule ^([A-Za-z0-9]+)/?$ ?a=b&content=$1 [L,QSA]

The rules work just fine, but my issue is in the stylesheet not affecting the page at all. I am not using a relative path in my stylesheet link, and I checked the DOM tree which confirms the stylesheets are "loaded". It's weird, they're being found, but just not being applied.


Solution

  • Add the following at the top of the .htaccess to prevent it from rewriting actual URL's:

    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]