Reputation: 397
I am trying to find a way to exclude image files and css files from my mod_rewrite permissions
Options +FollowSymLinks
RewriteEngine On
#SecFilterInheritance Off
ErrorDocument 404 /fourohfour.php
RewriteCond %{HTTP_HOST} ^(myurl\.com)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !\.(?:css|png|jpe?g|gif)$ [NC,OR] #my attempt at excluding
RewriteRule ^articles/([^/]+)/([^/]+)/?$ /article.php?id=$1&articleTopic=$2 [QSA,L]
Problem is with the exclusion line isn't quite accurate and I need help with it
If I go to any phpscript in my directory that isn't included in my .htaccess rewrite.. say for isntance www.myurl.com/articlelinks.php I get redirected to this:
http://www./articlelinks.php
To complicate things further:
If I go to: http://www.myurl.com/articles/1/Dorsal+and+Volar+Intercalated+Segment+Instability+(DISI+and+VISI) the CSS files don't load
If I go to:
http://www.myurl.com/articles.php?id=1&articleTopic=Dorsal+and+Volar+Intercalated+Segment+Instability+(DISI+and+VISI) the proper document is loaded with css and images
Please help?
Upvotes: 1
Views: 230
Reputation: 143906
You have an OR
flag in your condition, but there is no other condition after it, and that makes mod_rewrite think: %{REQUEST_URI} !\.(?:css|png|jpe?g|gif)$
or (anything). Try removing the OR
RewriteCond %{REQUEST_URI} !\.(?:css|png|jpe?g|gif)$ [NC]
RewriteRule ^articles/([^/]+)/([^/]+)/?$ /article.php?id=$1&articleTopic=$2 [QSA,L]
The reason your CSS isn't loading is probably because you're using relative URL paths in your document. Try either changing those links to absolute URL paths (starts with a /
) or add this to the page's header:
<base href="/" />
The blank host problem, not sure why that's happening. Try adding this condition:
RewriteCond %{HTTP_HOST} !^$
so that the rule looks like:
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} ^(myurl\.com)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
Upvotes: 1