SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Friendly Url Problem

    Hello,

    I'm trying to create a friendly url to rewrite something like
    domain.com/index.php?cat=catid&game=gameid to
    domain.com/catid/gameid

    I have this code

    RewriteEngine on
    RewriteRule ^([_A-Za-z0-9]+)/([_A-Za-z0-9-]+)/?$ index.php?cat=$1&game=$2

    The redirection works. However, the problem is that all my images and style sheets are not loading anymore. It tries to load the sheets / images off of the new folders /catid/gameid.

    How can I fix this so that the redirect works and my style sheets and images always load from the root directory.

    Thanks in advance,
    Armin
    Online Games - Play Free Online Games
    Arcade Games - Tons of Arcade Games
    Watermark Tool - Protect your Photos

  2. #2
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Put these lines before your RewriteRule:
    Code:
    RewriteCond %{REQUEST_FILENAME}  -d
    RewriteRule  ^.*$  -  [L]
    
    RewriteCond %{REQUEST_FILENAME}  -f
    RewriteRule  ^.*$  -  [L]
    They basically tell to leave existing directories or files alone.

  3. #3
    .* draziW tnioPetiS *. bronze trophy
    Join Date
    Jun 2004
    Location
    "Then I figure the most good good guy will win."
    Posts
    1,666
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks like kyberfabrikken has you covered.

    I would like to point-out this article by Dklynn... Especially the info under the heading of "Where did my images, js and css files go?" Maybe it will also be of some help?

    Cheers,
    Micky

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the replies.

    I tried the .htaccess with

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [L]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^.*$ - [L]
    RewriteRule ^([_A-Za-z0-9]+)/([_A-Za-z0-9-]+)/?$ index.php?CAT=$1&GAME=$2

    It doesnt seem to be doing anything. It still doesn't load the css and images.
    My css is located in root folder and my images are located in /images

    I also ready the article you suggested, but I do not want to put absolute path links in my image and style hrefs.

    Please help
    Online Games - Play Free Online Games
    Arcade Games - Tons of Arcade Games
    Watermark Tool - Protect your Photos

  5. #5
    .* draziW tnioPetiS *. bronze trophy
    Join Date
    Jun 2004
    Location
    "Then I figure the most good good guy will win."
    Posts
    1,666
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total shot in dark, but have you tried moving the last Rewrite rule as the first item after the "RewriteEngine on"? Not sure if that will help though. If not, I completely apologize for wasting your time.

    Edit:

    Doh, just re-read the post by Kyb:
    Put these lines before your RewriteRule:
    Sorry for wasting you time on this one.


    M

  6. #6
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I still can't get the redirection to work.

    This is what I have now and it messes up all styles and pictures. It tries to load everything off of the directories /[category]/[game].


    Code:
    ErrorDocument 400 /index.php
    ErrorDocument 402 /index.php
    ErrorDocument 403 /index.php
    ErrorDocument 404 /index.php
    ErrorDocument 500 /index.php
    
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME}  -d
    RewriteRule  ^.*$  -  [L]
    RewriteCond %{REQUEST_FILENAME}  -f
    RewriteRule  ^.*$  -  [L]
    RewriteRule ^([_A-Za-z0-9]+)/([_A-Za-z0-9-]+)/?$ index.php?CAT=$1&GAME=$2
    There must be some easy way to fix this using this htaccess file.

    Thank You,
    Armin
    Online Games - Play Free Online Games
    Arcade Games - Tons of Arcade Games
    Watermark Tool - Protect your Photos

  7. #7
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure if it makes any difference, but try sticking this line before RewriteEngine On
    Options FollowSymLinks

    If it still doesn't work, what do you get back, when you request an image (Type its address directly in the browsers address-bar)?

  8. #8
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It still doesn't work.

    When I do an image request directly like localhost/images/arrow.gif, it loads the image fine, but when I go to localhost/[category]/[game], the styles and images are not loaded.

    Armin
    Online Games - Play Free Online Games
    Arcade Games - Tons of Arcade Games
    Watermark Tool - Protect your Photos

  9. #9
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What does the HTML for your image-tag look like? You need to start with a leading / or use absolute URLs, otherwise, the browser will request relative to the path, as it sees it.

  10. #10
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, first I changed all my urls from "images/.." to "/images/..".
    However, the images still aren't loading under url /[category]/[game]

    When i changed my styles.css to /styles.css, it it started loading those properly.
    I also have background images inside styles.css and those ARE loading properly as well.

    However, when I go to home page, all images and styles are loading properly. So now, the only thing that seems messed up is that the images under /[category]/[game] are not loading, everything else looks ok.

    Armin
    Online Games - Play Free Online Games
    Arcade Games - Tons of Arcade Games
    Watermark Tool - Protect your Photos

  11. #11
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Must be your paths, that are wrong. If you load a page under /[category]/[game] and select view source in your browser -- what is the exact content of your images src-attribute?

  12. #12
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the exact src of an image under /[category/[game] is
    "/images/[imagename].gif". All images are like that.

    And when I right click properties on an image that is not loaded, it says
    http://localhost/images/[imagename].gif, but its suppose to be
    http://localhost/images/site/[imagename].gif

    Armin
    Online Games - Play Free Online Games
    Arcade Games - Tons of Arcade Games
    Watermark Tool - Protect your Photos

  13. #13
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So you run your site from a subfolder?
    / will refer to the top-level of your hostname. If you need to run the site from a subfolder, you will have to create absolute URLs.


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
  •