Odd CSS side effect with .htaccess

Ok, so I’ve written a .htaccess file change the url from:
localhost/MyWebsite/public/category1/category2/etc/ to localhost/MyWebsite/public/index.php?path=category1/category2/etc/

This seems to work fine:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteBase /public/
RewriteRule ^(.*)$ index.php?path=$1

For some reason the .css links are broken whenever viewing a dynamic url.

  • but a simple <base> tag to the index.php fixes that.

And with it all appears to work fine however there’s some odd things that aren’t working when viewing a dynamic url.

For example, this is the HTML generated for a nav bar:

<div id="backnav">
<ul>
<li><a href="page1/">page1</a></li>
<li><a href="page2/">page2</a></li>
<li><a href="page3/">page3</a></li>
<li><a href="page4/">page4</a></li>
<li><a href="page5/">page5</a></li>
<li><a href="page6/">page6</a></li>
<li><a href="page7/">page7</a></li>
</ul><!-- Unordered list of Links-->
</div>

Perfectly fine html, but only the page 6 & 7’s href’s are interpreted by the browser, the others are regarded a link-less text.
Other image hover effects don’t work.

If I disable the css the browser interprets all the html correctly. And css works correctly when not using .htaccess.

Has anyone heard of such a problem? Maybe if I could get access to the .css files only using .htaccess it would avoid this problem?

RK,

It’s likely that the other part you didn’t read in the tutorial (about inappropriate use of (.*) ) is the problem here, too.

ON the other hand, if you have MultiViews active or have other mod_rewrite directives in your .htaccess which are ordered before your code above, they’ll take precedence and cause inappropriate redirections, too.

IMHO, time to actually read the tutorial and view a few of the examples to wrap your head around the simple logic of mod_rewrite.

Regards,

DK

Turns out all problem above are from the css file alone… anyway…

I’ve done a bit more research. I think this is a more appropriate rule, do you agree?

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteBase /public/
RewriteRule ^([a-z0-9_/.]+)$ index.php?path=$1 [NC]

RK,

Options +FollowSymLinks should already be in your server’s conf file, there is no Redirect for mod_rewrite to UNDO with the RewriteBase (so this should go in the public subdirectory’s .htaccess otherwise and you really do NOT want the No Case flag to operate on a RewriteRule ({REQUEST_URI}'s are case sensitive) but, other than that, fine. :nono:

Regards,

DK

Thanks DK