SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast NickR25's Avatar
    Join Date
    Feb 2009
    Location
    Tampa, FL
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    .htaccess rewrite rule

    Hey guys,

    I'm in need of a rewrite rule that I am not sure is possible.

    Here's the scoop:
    My blog currently sits in the root of my domain (http://www.adminaddict.net).
    We plan to move the blog to its own directory (/blog) and replace the root with an index/homepage with links to our various services and resources.

    Doing this would naturally cause all links to our blog articles (in the formation of adminaddict.net/123-article-title) to become broken.
    If we implemented a rewrite rule where all attempts of accessing adminaddict.net/xyz are redirected to adminaddict.net/blog/xyz then our homepage would never be accessible.

    So here's what I want to do (if it's even possible):
    "If the URL is in the format of adminaddict.net/(a-number)-(text), then redirect to /blog/(a-number)-(text). Otherwise (for example, if the URL is /forum), don't redirect."

    So here is how it should be:

    adminaddict.net/ -> not redirected
    adminaddict.net/forum/xyz -> not redirected
    adminaddict.net/directory -> not redirected
    adminaddict.net/123-blog-article -> adminaddict.net/blog/123-blog-article

    Is this possible?

    Thanks.
    Best Regards,
    Nick
    AdminAddict

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

    On the surface, this appears to be an easy problem with two possible solutions:

    1. Merely check whether the directory/file exists before redirecting

    OR

    2. Use the apparent fact that your blog URIs do not have a dot character in them to redirect extensionless URIs to the blog subdirectory.

    If you need help on either, please check the tutorial linked in my signature then show your code here. I'm happy to show how to correct minor errors and provide explanations as to why they are necessary.

    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
  •