SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Subdomain to Subdirectory Rewrite

    Hello,

    Looking for some more help with rewrite rules, here's the older structure:

    subdomain.example.com/YYYYMMDD-title-permalink-slug/

    New structure:

    HTML Code:
    http://www.example.com/subdomain/YYYY/MM/DD/title-permalink-slug/
    Thanks,
    Grant

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

    What's so hard about that? It's trivial to cut up a date string like that!
    Code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} !^www\.example\.com$
    RewriteCond %{HTTP_HOST} ^([a-z]+)\.example\.com$
    RewriteRule ^(\d{4})(\d{2})(\d{2})-([a-z]+)-([a-z]+)-([a-z]+)/ http://www.example.com/%1/$1/$2/$3/$4-$5-$6/ [R=301,L]
    # note, with lack of definition, I've assUmed title, permalink and slug were strictly lowercase letters
    You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It's helped may members and should help you, too.

    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 Member
    Join Date
    Jul 2011
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What if I don't know what the permalink will be? Could be 3 words, could be 12?

    Thanks,
    Grant

    PS - I'll definitely check out your mod-rewrite article once I get this project complete. Always seem to be running into them. Thanks

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

    If you use multiple words in your "permalink" example, then you must account for the words by changing the spaces (or suffering the %20 which browsers and servers will use instead of a space character). I provide the arguement in my tutorial for changing to _'s rather than the more common -'s because hyphens are commonly found in text whereas _'s are not and changing them back before accessing your database (I've even provided sample PHP code for each). Also, UPPERCASE letters should be accounted for, too. An example of this (with some punctuation characters, too) is used in the navigation at http://wilderness-wally.com.

    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


Tags for this Thread

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
  •