Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: mod rewrite (PHP URL)

  1. #1
    Join Date
    Oct 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question mod rewrite (PHP URL)

    Hey, I know almost nothing about the proper usage of mod rewrite, so I would appreciate it if someone could help me out.

    I need:
    Code:
    http://www.site.com/index.php?p=view&article=article name here
    Converted (via mod rewrite) into
    Code:
    http://www.site.com/article/article-name-here/
    Thanks in advance!

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    RewriteEngine on
    
    RewriteRule ^/article/([^/]+)/?$ /index.php?p=view&article=$1
    ... if I remember correctly.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Oct 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Doesn't seem to be working

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Everything is set up correctly?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    This is what I've seen in the past. I've never used it, but it's worth a try?

    Code:
    RewriteEngine On
    Options +FollowSymlinks
    RewriteRule ^index/(.*).php index.php?action=$1
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  6. #6
    Join Date
    Oct 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    well after reading through several tutorials, and your post, I am very confused.

    The links on my page will be:

    Code:
    http://www.site.com/article/article-name-here/
    Now obviously that is not a real url, because those "directories" don't exist.

    Thats why I need the above to be interpreted by the server as:
    Code:
    "http://www.site.com/index.php?p=view&article=article name here"
    . I don't want it to display that ugly url though. I mean the whole point of this is to "nicen" the url (be it for people or search engines).

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    RewriteRule ^index/(.*).php index.php?action=$1
    No, that expression is wrong for the situation you described. You'd want:
    Code:
    RewriteRule ^article/([^/]+)/  index.php?p=view&article=$1
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Oct 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok that seems to work.

    Sadly the new (static) page seems to take almost 3 seconds to load (before it displays anything), Im guessing thats because of the re-write action.

  9. #9
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    Thanks Twey

    I think he's misunderstanding though...how it works.
    First of all, you're using Apache right?
    Second, did you set up a httpd.conf AND a .htaccess file?
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

  10. #10
    Join Date
    Mar 2006
    Location
    Cleveland, Ohio
    Posts
    574
    Thanks
    6
    Thanked 5 Times in 5 Posts

    Default

    Ok, nevermind. Haha. Maybe he did understand.
    Thou com'st in such a questionable shape
    Hamlet, Act 1, Scene 4

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
  •