Mod_rewrite rule problem

Discussion in 'Apache' started by Rashy, Nov 10, 2008.

  1. #1
    Site url:
    http://www.sitename.com/products.php?cat=1&page=1
    OR
    http://www.sitename.com/products.php?cat=1
    OR
    http://www.sitename.com/products.php
    Code (markup):
    Want it to become like this:
    http://www.sitename.com/products/category/1/page/1
    OR
    http://www.sitename.com/products/category/1
    OR
    http://www.sitename.com/products
    (Respectively)
    Code (markup):
    Mod_Rewrite Code i am using:
    <IfModule mod_rewrite.c>
    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^products/category/(.*)/page/(.*)$ products.php?cat=$1&page=$2 [L]
    RewriteRule ^products/category/(.*)$ products.php?cat=$1 [L]
    RewriteRule ^products$ products.php [L]
    </IfModule>
    Code (markup):
    But its not working at all :(
    Can anyone tell me where am i going wrong ?
     
    Rashy, Nov 10, 2008 IP
  2. vishwaa

    vishwaa Well-Known Member

    Messages:
    271
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    138
    #2
    If this doesn't work,
    1) please check that your server supports mod rewrite.
    2) Ensure the correct path of "products.php"
    3) Verify your server error log
     
    vishwaa, Nov 10, 2008 IP
  3. Rashy

    Rashy Peon

    Messages:
    20
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks vishwaa for helping :)
    but still its not working :(
    1) i guess if redirection through htaccess is working so it should imply that mod_rewrite is also working ... do correct me if i am wrong !?!
    2) products.php file is in the same folder as the .htaccess file.
    3) there are no error logs for this file or domain name :(

    Can you please get me out of this strange problem ?

    Edit: Opened a support ticket to reinstall mod_write on the server... hope that does the trick... but still waiting for it to work :(
     
    Rashy, Nov 10, 2008 IP
  4. vishwaa

    vishwaa Well-Known Member

    Messages:
    271
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    138
    #4
    Okay. What are you getting when accessing the new urls? Just blank page or home page?
     
    vishwaa, Nov 10, 2008 IP
  5. Rashy

    Rashy Peon

    Messages:
    20
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    When i am opening the old URL's:
    http://www.sitename.com/products.php?cat=1&page=1
    OR
    http://www.sitename.com/products.php?cat=1
    OR
    http://www.sitename.com/products.php
    Code (markup):
    They are working like they should....But if i manually type in the new URL's
     http://www.sitename.com/products/category/1/page/1
    OR
    http://www.sitename.com/products/category/1
    OR
    http://www.sitename.com/products
    (Respectively)
    Code (markup):
    I get the page but without any CSS styling or images just text.... what does that mean ?
     
    Rashy, Nov 11, 2008 IP
  6. vishwaa

    vishwaa Well-Known Member

    Messages:
    271
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    138
    #6
    So you are getting the correct pages with mod written urls but css and images are missing, right? If so, mod rewrite works fine in your case.

    Mod rewrite just make your new urls work. You will need to change the html/php code to make the css/images/urls to work properly.

    For ex.
    1) use absolute path like "/css/style.css" instead of "../css/style.css" for css/images/urls wherever possible.
    2) change the html code to reflect the new urls ("/products.php?cat=1&page=1" should be "/products/category/1/page/1")
     
    vishwaa, Nov 11, 2008 IP
  7. Rashy

    Rashy Peon

    Messages:
    20
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    yes i am getting the page without any CSS or images but that they are coming only when i manually type in the URL they are not getting converted by there own :confused:
    And once they are getting rewritten on there own then i will have to change the relative paths like css/style.css to absolute ones
    http://sitename.com/css/style.css
    Code (markup):
    as you say :confused:
    But that is the case only when the URL are getting rewritten on there own :( as for now i have to manually enter the new URL....
     
    Rashy, Nov 11, 2008 IP
  8. vishwaa

    vishwaa Well-Known Member

    Messages:
    271
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    138
    #8
    Rashy, mod rewrite does nothing else other than translating your seo friendly url to actual url. YOU only have to apply the new url structure to your html code. Until you do this, you will have to manually enter the new url and no conversion will occur as you expect. Hope you understand this.
     
    vishwaa, Nov 11, 2008 IP
  9. Rashy

    Rashy Peon

    Messages:
    20
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    oh [​IMG] i didn't knew that i have to change my URL structure too[​IMG] i thought by using mod_rewrite only my URL structure will automatically get rewritten [​IMG] ok now i get it thanks for clearing the things out [​IMG]
     
    Rashy, Nov 11, 2008 IP
    vishwaa likes this.