Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Apr 2007
    Posts
    317
    Thanks
    24
    Thanked 3 Times in 3 Posts

    MOD Rewrite Problem with PHP Pages

    Hi guys,

    I have a site which is fully dynamic and generated from a Mysql database. I am having an issue with my .htaccess mod rewrite. The problem i am having is that my urls work fine, however my css file seems to be failing to load. I'm not so good with mod rewrite so i was hoping someone out there has a simple solution for me.

    This is the structure of my URL

    http://www.example.com/category/subcat

    and this is what is inside my .htaccess file at my root directory.

    Code:
    RewriteEngine On
    RewriteRule ^go/(.+)/(.+)$ hop_redirect.php?id=$2&%{QUERY_STRING}
    RewriteRule ^(.+)/(.+)$ search.php?q=$2&%{QUERY_STRING}
    RewriteRule ^(.+)/(.+)/(.+)$ view_product.php?id=$3
    RewriteCond $1 !^(index\.php|images|files|fckeditor|robots\.txt|css)[L]
    and this is how i call my css within the head of my pages

    Code:
    <link rel="stylesheet" media="all" type="text/css" href="css/menu.css" />
    I tried switching it to the full http directive but it still doesn't seem to load.

    Any help is appreciated. Thanks alot.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Try
    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^go/(.+)/(.+)$ hop_redirect.php?id=$2&%{QUERY_STRING}
    RewriteRule ^(.+)/(.+)$ search.php?q=$2&%{QUERY_STRING}
    RewriteRule ^(.+)/(.+)/(.+)$ view_product.php?id=$3
    RewriteCond $1 !^(index\.php|images|files|fckeditor|robots\.txt|css)[L]
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Apr 2007
    Posts
    317
    Thanks
    24
    Thanked 3 Times in 3 Posts
    I tried that but was unsuccessful. Any other thoughts?

    A strange note:
    If i put a forward slash in front of the $ sign my css works but my url rewrite does not.

  • #4
    GŁtkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    I'm not sure that will work, since the RewriteConds only modify the next rule, and there are still two more that can hijack that css.

    Putting it like this should work though:

    Code:
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^(.*)$ - [L]
    RewriteRule ^go/(.+)/(.+)$ hop_redirect.php?id=$2&%{QUERY_STRING}
    RewriteRule ^(.+)/(.+)$ search.php?q=$2&%{QUERY_STRING}
    RewriteRule ^(.+)/(.+)/(.+)$ view_product.php?id=$3
    RewriteCond $1 !^(index\.php|images|files|fckeditor|robots\.txt|css)[L]

  • Users who have thanked venegal for this post:

    macleodjb (05-02-2009)

  • #5
    Regular Coder
    Join Date
    Apr 2007
    Posts
    317
    Thanks
    24
    Thanked 3 Times in 3 Posts
    That worked perfectly. Thanks alot.

  • #6
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nice, I have been looking for a solution like this as well.

  • #7
    Regular Coder
    Join Date
    Apr 2007
    Posts
    317
    Thanks
    24
    Thanked 3 Times in 3 Posts
    I came across another issue. I am trying to implement a feed on the same website and i inserted another rewrite rule and it doesn't seem to be working properly.

    Here is what i inserted
    Code:
    RewriteRule ^feeds/(.+)/(.+)$ feeds/feeds.php?cat=$2%{QUERY_STRING}
    This is how my .htaccess file looks now.
    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -f [or]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^(.*)$ - [L]
    RewriteRule ^go/(.+)/(.+)$ hop_redirect.php?id=$2&%{QUERY_STRING}
    RewriteRule ^feeds/(.+)/(.+)$ feeds/feeds.php?cat=$2%{QUERY_STRING}
    RewriteRule ^(.+)/(.+)$ search.php?q=$2&%{QUERY_STRING}
    RewriteRule ^(.+)/(.+)/(.+)$ view_product.php?id=$3
    RewriteCond $1 !^(index\.php|images|files|fckeditor|robots\.txt|css)[L]
    I do have the folder named "feeds" on the testing server as well as a file within that folder named "feeds.php", however its giving me a 404 error.

    I wish i could get my head around how mod rewrite works so i could troubleshoot my own problems. But i'm not there yet so if you are so kind to help me out again i'd appreciate it. Thanks again.

  • #8
    GŁtkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    I'm not sure if this will solve your problem, but one thing that's going wrong with your script is the fact that you did not tell it to consider the added rule as the last one if matched.

    The way it is now, 'feeds/sth1/sth2' is rewritten to 'feeds/feeds.php?cat=sth2'.
    Then the next rule kicks in and rewrites 'feeds/feeds.php?cat=sth2' to 'search.php?q=feeds.php?cat=sth2', which is definitely not what you want.

    So, add [L] at the end of your new rule, or better yet, at the end of every rule you want to be the last one evaluated if matched.

    Furthermore you forgot a & in your new rule.

    Code:
    RewriteRule ^feeds/(.+)/(.+)$ feeds/feeds.php?cat=$2&%{QUERY_STRING} [L]

  • Users who have thanked venegal for this post:

    macleodjb (05-02-2009)

  • #9
    Regular Coder
    Join Date
    Apr 2007
    Posts
    317
    Thanks
    24
    Thanked 3 Times in 3 Posts
    Thanks alot i'll give that a try. The heat was getting too intense for me so i just removed the rule from the original .htaccess file and added a separate file under the feeds directory and got it working. I'd rather keep it all in one file, so thank you.


  •  

    Posting Permissions

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