SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member Games Junction's Avatar
    Join Date
    Dec 2004
    Location
    England
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mod_rewrite help!

    Hey,

    I need help on mod_rewrite. Ive read through lots of tutorials and im experimenting on my own hosting site to test things out.

    At the moment if you type www.srchosting.com/index.html it will redirect you to www.srchosting.com/index.php which is right.

    But I have been trying to do something like:

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^index\.html$ index.php
    RewriteRule ^index1\.html$ index.php
    RewriteRule ^index/([0-9][0-9])/$ index.php?prodID=$1
    </IfModule>

    And instead of just showing the index.php page and retrieving the prodID it actually keeps the page in the /index/ directory that does not exist. One of the broken images shows:

    http://www.srchosting.com/index/99/images/index_08.jpg

    but it should be www.srchosting.com/images/index_08.jpg. I also dont think that its loading the stylesheets because of this…

    Try looking at http://www.srchosting.com/index/99/ you will see that its only loaded the text lol.

    Please help!
    Beaver6813 SRC Hosting CEO
    www.srchosting.com - Safe. Reliable. Low Cost Web Hosting

  2. #2
    SitePoint Member Games Junction's Avatar
    Join Date
    Dec 2004
    Location
    England
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok ive been researching and found that you need to exempt .jpg, .gif files etc from the rewrite on another forum someone said to use:

    RewriteCond %{REQUEST_URI} !\.(exe|css|js|jpe?g|gif)$

    But that doesn't appear to do anything at all. Any ideas!
    Beaver6813 SRC Hosting CEO
    www.srchosting.com - Safe. Reliable. Low Cost Web Hosting

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Games,

    WHAT is it you're trying to do?
    Code:
    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^index\.html$ index.php
    RewriteRule   ^index1\.html$  index.php
    RewriteRule ^index/([0-9][0-9])/$ index.php?prodID=$1
    </IfModule>
    If you don't know whether your mod_rewrite is enabled, don't even try to be a webmaster! Just get rid of that IfModule wrapper!

    Second, placing the RewriteRules together like this ANDs them UNLESS you add a Last flag ([L]) after each one (to close each "statement").

    http://www.srchosting.com/index/99/images/index_08.jpg clearly does NOT match any of your regex so there is NO exclusion necessary.

    May I respectfully suggest that you read the SEO article linked to in my signature - it may show you what you're doing wrong.

    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

  4. #4
    SitePoint Member Games Junction's Avatar
    Join Date
    Dec 2004
    Location
    England
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have that if part in there as i am developing a script that will be deployed on various servers. And i dont know whether EVERY person using it will have mod_rewrite enabled!!!

    What are you going on about regex? I want the images to be excluded from the rewrite so the url they try to load the images from stays the same. As at the moment loading from http://www.srchosting.com/index/99/images/index_08.jpg is wrong!

    EDIT: Ive figured that the easiest way is to just simply make the images load from an absoloute location.
    Beaver6813 SRC Hosting CEO
    www.srchosting.com - Safe. Reliable. Low Cost Web Hosting

  5. #5
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,672
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Games,

    THAT is a good enough reason to use IfModule (probably the ONLY good reason, IMHO).

    REGEX is how you tell Apache what you want done. It's also how you started this post. The problem that's causing your mod_rewrite not to work is that you've used the START anchor when you specifically do NOT want to use the start anchor (the ^ tells mod_rewrite that the {REQUEST_URI} MUST START WITH ... and the $ says that it must END there).

    Just remove your ^ and you should be okay - so long as you're not sending the incorrect MIME type!

    Regards,

    DK





    Quote Originally Posted by Games Junction
    I have that if part in there as i am developing a script that will be deployed on various servers. And i dont know whether EVERY person using it will have mod_rewrite enabled!!!

    What are you going on about regex? I want the images to be excluded from the rewrite so the url they try to load the images from stays the same. As at the moment loading from http://www.srchosting.com/index/99/images/index_08.jpg is wrong!

    EDIT: Ive figured that the easiest way is to just simply make the images load from an absoloute location.
    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


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
  •