Htaccess help

Discussion in 'Programming' started by anuradhan, Aug 2, 2011.

  1. #1
    hi DP Programmers,

    I need your help fixing problem in the following codes.

    here is 2 lines of my site htaccess code:
    RewriteRule ^(.*)/blogs /sites/blog.php?url=$1
    RewriteRule ^(.*)/blogs/(.*) /sites/blog.php?url=$1&id=$2

    and while, accessing the following url in site,
    somesite.com/akildeoza/blogs - it works correctly.
    somesite.com/akildeoza/blogs/1 - not working properly  (akildeoza is not getting posted)

    may i know, whats wrong here.


    Thanks for all help in advance.
    warm regards
    anuradhan
     
    anuradhan, Aug 2, 2011 IP
  2. i8k

    i8k Greenhorn

    Messages:
    58
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #2
    Check to make sure your folder path matches what the rewrite rule is sending the blog.php

    RewriteRule ^(.*)/blogs /sites/blog.php?url=$1 - folder/blogs is sent as /sites/blog.php?url=folder

    RewriteRule ^(.*)/blogs/(.*) /sites/blog.php?url=$1&id=$2 - /folder1/blogs/folder2 is sent as /sites/blog/php?url=folder1&id=folder2
     
    i8k, Aug 3, 2011 IP
  3. anuradhan

    anuradhan Active Member

    Messages:
    371
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    65
    #3
    what do you mean by folder path here ???

    please check this: (in above urls i specified)
    when users types the following url,
    somesite.com/akildeoza/blogs, the url (/sites/blog.php?url=$1) is correctly retrieving akildeoza value 
    whereas in somesite.com/akildeoza/blogs/1 , the url is retrieving some other value like url/sites/blog.php , actually it should get the value akildeoza.

    you got clear ???

     
    anuradhan, Aug 3, 2011 IP
  4. i8k

    i8k Greenhorn

    Messages:
    58
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #4
    akildeoza is a folder no?

    akildeoza/blogs == /sites/blog.php?url=akildeoza

    akildeoza/blogs/1 == /sites/blog.php?url=akildeoza&id=1

    you need to check blogs.php to see that it is making the path correctly for $url/blogs/$id/

    print the error message here may help also
     
    i8k, Aug 3, 2011 IP
  5. anuradhan

    anuradhan Active Member

    Messages:
    371
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    65
    #5
    no, there is no akildeoza folder in server.
    thats the reason i've written the above htaccess rewrite code.which will automatically retrieve data from sites/blog.php using the url parameter
    thing is, 2nd line htaccess code messup with the 1st line of code,as they are similar.

    need to fix this.
     
    anuradhan, Aug 3, 2011 IP
  6. anuradhan

    anuradhan Active Member

    Messages:
    371
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    65
    #6
    Thanks for your suggessions @i8k.
    Finally after some trials, found the solution.

    combined these 2 lines :
    RewriteRule ^(.*)/blogs /sites/blog.php?url=$1
    RewriteRule ^(.*)/blogs/(.*) /sites/blog.php?url=$1&id=$2
    to single line : 
    RewriteRule ^(.*)/blogs(/?)(.*) /sites/blog.php?url=$1&id=$3

    now it works perfectly :) :)
     
    anuradhan, Aug 3, 2011 IP