SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot RyanKing1809's Avatar
    Join Date
    Oct 2011
    Location
    Melbourne, Australia
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:
    Code:
    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:
    Code:
    <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?

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,680
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Zealot RyanKing1809's Avatar
    Join Date
    Oct 2011
    Location
    Melbourne, Australia
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?
    Code:
    Options +FollowSymLinks
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteBase /public/
    RewriteRule ^([a-z0-9_/.]+)$ index.php?path=$1 [NC]

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,680
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  5. #5
    SitePoint Zealot RyanKing1809's Avatar
    Join Date
    Oct 2011
    Location
    Melbourne, Australia
    Posts
    170
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks DK


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •