SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot Coastal Web's Avatar
    Join Date
    Jan 2006
    Location
    Oregon, U.S.
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    301 redirect old pages?

    Hi guys, sorry for the wrong forum, there isn't an apache thread.
    l'm trying to use htaccess to 301 redirect a bunch of old pages to a newly improved page. -- l have a lot of them and l was wondering if there was a cleaner way of doing this?

    Code:
    Redirect 301 /page1/ /newpage/
    Redirect 301 /page1 /newpage/
    Redirect 301 /page2/ /newpage/
    Redirect 301 /page2 /newpage/
    Redirect 301 /page3/ /newpage/
    Redirect 301 /page3 /newpage/
    Is there something like this l can do?
    Code:
    Redirect 301 (/page3|/page2|page1) /newpage/
    Another point to mention, l have each URL listed twice, because it doesn't seem to work because of the trailing slash on the old page -- sometimes it's there for visitors sometimes it's not.

  2. #2
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Not that I know of and I looked for a long time. Here is the 301 I use. Make sure you use full paths on the new URL

    # 301 permanent redirect about.html to about-us.html
    redirect 301 /about.html http://www.mydomain.com/about-us.html

    And about the trailing slash. If using full paths doesn't fix that then implement this. This will add the trailing slash to your domain and folders among other things.

    http://www.websitecodetutorials.com/...-to-folder.php

  3. #3
    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)
    CW,

    mod_alias's Redirect can't use a regex engine so, no, your suggestion won't work. I'm not an expert in mod_alias but you can lookup RedirectMatch and it just might be able to help you.

    mod_alias, because of the regex engine, is slower but far more powerful (it can look at more than the {REQUEST_URI}) so what you've done is close to:

    Code:
    RewriteEngine on
    RewriteRule (page1|page2|page3)/? newpage [R=301,L]
    ... but that's only after you slap yourself silly for allowing trailing /'s on files (that should be reserved for directories).

    If you need more information about mod_rewrite, 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

  4. #4
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,245
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    RedirectMatch seems to be designed for situations exactly like this.

    RedirectMatch 301 ^/(?:page1|page2|page3)/?$ /newpage/
    "First make it work. Then make it better."


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
  •