SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    301 redirect for all combinations

    Hello everyone,

    I have made a change to my site so that it is no longer in a subdirectory of my root domain. (it is now in the root of the domain).

    I have made the move successfully but I would like to put a 301 redirect into my htaccess so that people visiting the old links make it to the new site.

    A sample link on my site has gone from www.mysite.com/olddirectory/samplelink to www.mysite.com/samplelink

    So basically, I am looking for something that would say if any one goes to www.mysite.com/olddirectory/*wildcard_here* they would be redirected to www.mysite.com/*wildcard_here* .


    On another site, I was doing something similar but in the other direction. I had moved a site into a directory from the root, so I had

    Code:
    RewriteEngine on 
    RewriteCond $1 !^newdirectory 
    RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]
    Is there any way to do what I am trying to do? It is important that if some one goes to a directory that is not "olddirectory", they should not be redirected.

    Thank you in advance

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

    That's so simple that you don't even need mod_rewrite to do that! Look at Apache's mod_alias which should get you to:
    Code:
    Redirect permanent /olddirectory http://example.com/
    As a webmaster (just as a carpenter), using the correct tool for the occasion is important!

    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 Enthusiast
    Join Date
    Apr 2009
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for the reply.

    The problem I am having is that I have thousands of urls within the olddirectory.

    As far as I can tell, this solution only works for people going directly to the root of /olddirectory. Am I correct in that statement?

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

    Did you try it? Okay, obviously not! From that response, I'm sure you didn't even go look at the Apache.org page! Oh, well, when you do, you'll learn that mod_alias will work on that directory as specified (removing it from the URLs with a permanent redirection).

    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

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Posts
    66
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    dk,


    Thank you for the help!

    You were correct in your assumption that I did not try your suggestion. At the time, I did not have access to my ftp, so I could not try it. I did however read the link you provided, I was just confused as there was no wildcard apparent in the redirect, so I did not expect it to work.


    I have now tested it and it is working perfectly! Thank you for your help!

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



    If you're still confused, PLEASE ask questions as it's important to me that you know WHY things work (so you can help others learn when you get the chance).

    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
  •