SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict Banana Man's Avatar
    Join Date
    Dec 2005
    Posts
    386
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Rewrite root directory url's

    Hi,

    I'm trying to get my article url's to just have the domain name, article title and article id e.g. www.mydomin.com/article-title-1.

    I can do this with the following:

    RewriteRule ([A-Za-z0-9-]+)-([0-9]+) dynamic/index.php?dynamic_url=$1&id=$2

    but this seems to interfere with any file in the entire site that ends in the format of a string/number-number e.g. www.mydomain.com/images/image-1

    Is their a way of specifying this rewrite condition on to files appearing directly after the domain name?

    Thanks!

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,148
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    You can use ^ to ensure your pattern starts matching at the beginning of the string, and $ to ensure it finishes matching at the end of the string. Otherwise, your pattern could be matching any middle portion of your strings.

    RewriteRule ^([A-Za-z0-9-]+)-([0-9]+)$ dynamic/index.php?dynamic_url=$1&id=$2
    "First make it work. Then make it better."

  3. #3
    SitePoint Addict Banana Man's Avatar
    Join Date
    Dec 2005
    Posts
    386
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Brilliant! That's got it sorted.


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
  •