I must just not understand .htaccess at all

Discussion in 'PHP' started by absentx, Sep 20, 2010.

  1. #1
    Okay I have been up all night trying to get some url rewrites to work and clearly there is something fundamental I am not getting.

    I am about a year and a half into programming with php and I want to get some of my dynamic urls looking better...but clearly I am missing someting.

    Okay. Here is my url:

    www.mysite.com/neato.php?id=mo&junk=great

    Nifty online url rewrite tool tells me to enter the following into htaccess:

    Options +FollowSymLinks
    RewriteEngine on

    RewriteRule neato/id/(.*)/junk/(.*) neato.php?id=$1&junk=$2

    ...and then my URL's will look like this:

    www.mysite.com/neato/id/mo/junk/great/

    Not perfect, but it is better than nothing until I learn more about mod rewrite and can get the URL's truly how I want them.

    Now the problem I am having is I cant get it to work at all!!

    If I am linking to neato.php (and passing id and junk) how do I get neato.php to pick up those variables when all the sudden now I am linking to neato/id/'$row['id']/junk/$row['junk'] ?? What should my $_GET variables be on the receiving page so my queries work???

    Ahhhckkk...this is just really frustrating...I am sure it is super simple but there is some concept here that I am completely missing.

    If someone could walk me through the constructs of doing this beyond just what I have to put in the .htaccess file that would be appreciated!

    Thanks
     
    absentx, Sep 20, 2010 IP
  2. dreamconception

    dreamconception Peon

    Messages:
    55
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Look at the rewriterule;

    RewriteRule neato/id/(.*)/junk/(.*) neato.php?id=$1&junk=$2


    It states that the URL neato/id/$row['id']/junk/$row['junk'] should be parsed into neato.php?id=$row['id']&junk=$row['junk']

    I hope this clears up how rewrite works :) You have an apostrophe just before $row['id'] that might cause trouble.
     
    dreamconception, Sep 20, 2010 IP
  3. seoforall

    seoforall Peon

    Messages:
    40
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    when i was exactly at your point i did the following

    install a wordpress (standard in cPanel) and take a note of the default .htaccess file, then login to your wordpress admin and go into configs and make "seo friendly URLs" then take a look at the .htaccess again. It does the trick
     
    seoforall, Sep 20, 2010 IP
  4. absentx

    absentx Peon

    Messages:
    98
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Should I have to do any reworking of my base code?

    See that is what I dont get. Everyone and everything makes it seem like all i ave to do make the changes to htaccess and everything will magically work...but that isn't what happens.

    See its not the htaccess part I dont get, its how I have to restructure or change things else where to make it a well oiled machine.

    As I sit right now, I have cleaned it up a bit and the link I am trying to get to is www.mysite.com/neato/stuff/great/

    (actual url is now www.mysite.com/neato.php?stuff=great)

    my htaccess is as follows:
    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule neato/stuff/(.*)/ neato.php?stuff=$1
    RewriteRule neato/stuff/(.*) neato.php?stuff=$1

    when I hit that link its just a mess! None of my includes or queries work and I just have no idea what I am doing wrong.
     
    Last edited: Sep 20, 2010
    absentx, Sep 20, 2010 IP