SitePoint Sponsor

User Tag List

Results 1 to 19 of 19
  1. #1
    SitePoint Member
    Join Date
    Nov 2004
    Location
    hanoi
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Apache, mod_rewrite ...how to?

    hi everyone

    I have a question about mod_rewrite.

    My link like this http://polestartravel.com/index.php?page=trekkingtours
    it is not friendly with Search Engines at all.
    Now I want it change to http://polestartravel.com/vietnam/trekkingtours
    by how can I do that?
    or whatever you can suggest?
    Please note that: I already finish my websites. All sites are completed.
    I've tried myself to change, but couldnot..

    I need your help men

  2. #2
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Moved to the right forum.

    Where did /vietnam/ come from, do you just want it in every link? Or will that change but have no effect on the link?
    Mike
    It's not who I am underneath, but what I do that defines me.

  3. #3
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I went to your website and you aren't even using that linking method anywhere on your site...
    Mike
    It's not who I am underneath, but what I do that defines me.

  4. #4
    SitePoint Member
    Join Date
    Nov 2004
    Location
    hanoi
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in every link the page, link could see like that http://mydomain.com/xxx/xxx.php(or html)

  5. #5
    SitePoint Member
    Join Date
    Nov 2004
    Location
    hanoi
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yep, I just ask for the mode_rewite and the link above just is demo example to ask.
    My site is still on localhost in my pc

  6. #6
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Ok, so you want a keyword in the link but not have it pass on to the other page. This should work I guess... you have to check the keyword to make sure it's not an actual directory.

    David will be along sometime to correct my code I'm sure


    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} ^(.*)/([A-Za-z0-9]+)/?$
    RewriteCond %1/ !-d
    RewriteRule ^(.*)/(.*)/?$ index.php?page=%2 [L]
    Last edited by Mike; May 12, 2005 at 04:01.
    Mike
    It's not who I am underneath, but what I do that defines me.

  7. #7
    SitePoint Member
    Join Date
    Nov 2004
    Location
    hanoi
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks man I will try and inform result tomorrow

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

    OUCH! You're putting me on the spot!

    Okay, I would have suggested:
    Code:
    RewriteEngine On
    RewriteRule ^vietnam/([a-z]+)/?$ index.php?page=$1 [L]
    ... which merely looks for the vietnam/whatever (lowercase ONLY!) with the optional slash (you can remove the /? if you're not going to have that in your links) and redirects to the index.php script with the query string of page=whatever.

    Piece of cake!

    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

  9. #9
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Well, I was goin to as well, but he made it sounds as if "vietnam" wouldn't be the only text used, i'd imaine he'll replace that with some of the pages keywords for SEO purposes.
    Mike
    It's not who I am underneath, but what I do that defines me.

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

    It must've been the hour 'cause I didn't catch that vietnam was a variable text field. If so, a similar "text field" atom ([a-z]+) would be use (and discarded - he didn't want that info in the redirection). However, that COULD lead to problems if he went to use other (real) subdirectories.

    Yeah, I **DO** have an aversion to the "EVERYTHING" atom (.*) as that can open things up to unexpected loops as well as hackers inserting unexpected directives in the redirection. Paranoia or philosoply, that's my excuse!

    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

  11. #11
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Yea I figured it would break the real directories so I trid to hack my way through pippo's code to do a check to see if it was a real dir or not. To be honest, I don't even know if the code I posted works

    As for the everything atom, in my example it's being discarded anyways, so it shouldn't matter... though I check all input via my php scripts.

    mod rewrite is nice though, as it lets me skip some error checking in PHP that would be redundant. If I just have [a-z] in mod rewrite, I don't need to check it in PHP
    Mike
    It's not who I am underneath, but what I do that defines me.

  12. #12
    SitePoint Member
    Join Date
    Nov 2004
    Location
    hanoi
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    by the way, my host server does not allow phpinfo() so how do I know that mod_rewrite turn on of not I am not sure that I can test mod_rewrite

  13. #13
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    just put this in your htaccess file:

    RewriteEngine On

    If it throws an error, you do not have mod rewrite installed
    Mike
    It's not who I am underneath, but what I do that defines me.

  14. #14
    SitePoint Member
    Join Date
    Nov 2004
    Location
    hanoi
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When I use .httaccess there'a error:

    Internal Server Error
    The server encountered an internal error or misconfiguration and was unable to complete your request.

    Please contact the server administrator, admin@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

    More information about this error may be available in the server error log.


    --------------------------------------------------------------------------------

    Apache/2.0.52 (Win32) mod_ssl/2.0.52 OpenSSL/0.9.7d PHP/5.0.2 Server at 127.0.0.1 Port 80

  15. #15
    SitePoint Member
    Join Date
    Nov 2004
    Location
    hanoi
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    plz tell me how to turn on mod_rewrite on windows localhost? I am using Xamp

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

    That's in Apache's httpd.conf file where it's commented out by default. Just remove the # at the start of the line and restart Apache - as covered in the article at datakoncepts.com/seo.

    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

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

    From the looks of your messages, you, too, have been copying and saving pippo's posts. I keep those around as the most valuable resource I have. I'm glad that someone else is smart enough to do that AND that you are willing to share time in this forum, too. THANKS!

    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

  18. #18
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    He's done a lot of mod rewrite code for me in the past, so I usually have a workable example right on my local machine here

    He hasn't had a lot of time lately to come around here so I'm trying to help out as much as I can

    I should be thaning you though, if you weren't here, there'd be just a dead forum
    Mike
    It's not who I am underneath, but what I do that defines me.

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


    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


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
  •