SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2004
    Location
    Denver
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need some simple (i think) mod rewrite help

    I've been trying to figure this out for a while now but I'm not having any luck.

    Here's what I'm trying to do.

    example.com/directory/index.php?article-title

    rewritten to just...

    example.com/directory/article-title

    I'm really new to mod rewrite and I've read several tutorials but still haven't gotten anything working. Any ideas out there? Thanks.
    Last edited by tristankelley; Feb 15, 2005 at 16:07.

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

    YOU have to rewrite your links in your webpages yourself! Mod_rewrite will rewrite back if you have it done correctly, i.e., changedirectory/article-title to index.php?article-title=article-title.

    Have a look at http://www.datakoncepts.com/seo for more details on setting up Apache and using mod_rewrite.

    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

  3. #3
    SitePoint Zealot
    Join Date
    Sep 2004
    Location
    Denver
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmm. I guess I don't have any clue about mod rewrite.

    Does Sitepoint use mod rewrite to get URL's like:

    http://www.sitepoint.com/article/push-pull-best-cms

    Thanks.

  4. #4
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Give me a PHP url and what you want it converted into using mod_rewrite. And I'll see what I can do

  5. #5
    SitePoint Zealot
    Join Date
    Sep 2004
    Location
    Denver
    Posts
    111
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have url's like:

    example.com/directory/index.php?title=article-title

    I would like them to look like

    example.com/directory/article-title

    Does that make sense?

  6. #6
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok first of all I'm assuming:

    a) You have .htaccess files enabled on you server
    b) You have mod_rewrite enabled on your server.

    Make a filename called '.htaccess' and place in it:

    Code:
    RewriteEngine On
    RewriteRule ^([A-Za-z-]+)/?$ index.php?title=$1 [L]
    Let me know if it works ok

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

    Dean's code is perfect IF you don't include any character other than the upper and lower case alphabet and the hyphen (dash). Be SURE that you stick to that in naming your titles (for the links).

    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
  •