URL Rewrite

Discussion in 'PHP' started by cn45896, Aug 4, 2011.

  1. #1
    I am not sure where to look as I have not really done anything with this before, but I want to be able to write out a URL like this:

    www.whatever.com/view/ipad2/4587

    and then when I get to index.php of the view directory, be able to pull the ipad2 product as a variable as well as the refID at the end. I have looked at how to rewrite URLs but this seems like the reverse. Any help is appreciated.
     
    cn45896, Aug 4, 2011 IP
  2. helpinghost

    helpinghost Active Member

    Messages:
    36
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    53
    #2
    While you gave us the URL you want to be the rewrite result, you did not give us the Source URL.
     
    helpinghost, Aug 4, 2011 IP
  3. cn45896

    cn45896 Guest

    Messages:
    140
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    the end page it would go to is index.php in the view folder
     
    cn45896, Aug 4, 2011 IP
  4. Darkhodge

    Darkhodge Well-Known Member

    Messages:
    2,111
    Likes Received:
    76
    Best Answers:
    1
    Trophy Points:
    185
    #4
    Darkhodge, Aug 4, 2011 IP
  5. cn45896

    cn45896 Guest

    Messages:
    140
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I can re-write the dynamic url to display like I want, but the URL that will be entered is static:
    www.whatever.com/view/ipad2/4587

    and when I get to index.php inside the view folder, I am not sure how to use the first directory after the view folder and pull that as a get variable. For example:

    $_GET['product'] = 'ipad'
     
    Last edited: Aug 5, 2011
    cn45896, Aug 5, 2011 IP
  6. Thorlax402

    Thorlax402 Member

    Messages:
    194
    Likes Received:
    2
    Best Answers:
    5
    Trophy Points:
    40
    #6
    The link that Darkhodge provided is exactly what you are looking for. It is a great tutorial from the looks of it.
     
    Thorlax402, Aug 5, 2011 IP
  7. Darkhodge

    Darkhodge Well-Known Member

    Messages:
    2,111
    Likes Received:
    76
    Best Answers:
    1
    Trophy Points:
    185
    #7
    Darkhodge, Aug 6, 2011 IP
  8. Andre91

    Andre91 Peon

    Messages:
    197
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #8
    Andre91, Aug 6, 2011 IP
  9. cn45896

    cn45896 Guest

    Messages:
    140
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Thanks guys. I have been trying to get something working, but cant seem to get the simplest example actually re-writing. It's a Wordpress site and I know the mod-rewrite is working as Wordpress is using it. I am putting new rules in the root .htaccess file, but nothing. Is there anything different when dealing with wordpress? The one folder I am wanting to direct links to is in the root and does not use the wordpress structure, just a simple php script to redirect to other sites.
     
    cn45896, Aug 7, 2011 IP
  10. Andre91

    Andre91 Peon

    Messages:
    197
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #10
    If you trust me enough, I can have a look at your site and what you're trying to achieve.
     
    Andre91, Aug 7, 2011 IP
  11. Thorlax402

    Thorlax402 Member

    Messages:
    194
    Likes Received:
    2
    Best Answers:
    5
    Trophy Points:
    40
    #11
    If you are using wordpress then it already has a built in setting for displaying urls this way. In the admin pages, go to settings->permalinks. You can define a custom setting to do exactly what you need.
     
    Thorlax402, Aug 7, 2011 IP
  12. cn45896

    cn45896 Guest

    Messages:
    140
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #12
    I know how permalinks work, but this is a separate folder located in the root directory just used for redirects. The issue is none of my re-write rules seem to take affect. But I know wordpress uses them so not sure why I can not alter it.
     
    cn45896, Aug 8, 2011 IP
  13. ausrixy

    ausrixy Peon

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    0
    #13
    just google mod rewrite and change your htdoc file .
     
    ausrixy, Aug 10, 2011 IP
  14. cn45896

    cn45896 Guest

    Messages:
    140
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #14
    I cant seem to find out why none of the rules I am adding work. There is already an htaccess file in the root that handles the Wordpress stuff which includes re write rules. But when I add anything like:

    RewriteRule ^([^/]*)/([^/]*)\.html$ /products/?prodname=$1&shopID=$2 [L]

    and then add a dynamic URL like products/?prodname=ipad&shopID=4561

    nothing the URL does not seem to change and it simply directs me to the dynamic path.

    Any thoughts on why nothing happens, or am I missing something?
     
    cn45896, Aug 11, 2011 IP
  15. Thorlax402

    Thorlax402 Member

    Messages:
    194
    Likes Received:
    2
    Best Answers:
    5
    Trophy Points:
    40
    #15
    Are there other Rewrite rules above this one that have [L] after then by any chance?
     
    Thorlax402, Aug 11, 2011 IP
  16. cn45896

    cn45896 Guest

    Messages:
    140
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #16
    I got it working, thanks guys.
     
    cn45896, Aug 11, 2011 IP
  17. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #17
    This guide might help you.
     
    ads2help, Aug 12, 2011 IP
  18. unknownpray

    unknownpray Active Member

    Messages:
    3,831
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    70
    #18
    Search Engines usually respond positively to URL rewrites. This is just like you telling a person that a shop has moved to another location. There is a plugin in Wordpress called 301 redirects that provides you this facility and for other html pages make sure that your hosting provides the necessary support. This is done by writing the code in a .htaccess file placed at the root directory.
     
    unknownpray, Aug 12, 2011 IP