Results 1 to 9 of 9
  1. #1

    htaccess redirect for entire directory

    I have set up an htaccess redirect for directories and for particular pages, but is there a way to redirect globally for any file in a particular directory?

    EX:
    I want to redirect abc.com/123/*.* to abc.com/456/*.*
    causing abc.com/123/anything.htm to forward to abc/456/anything.htm

    anything.htm index.htm topic.php --- all files in the directory

    The hard part: I wish to do this without listing every file in the directory in my htaccess file.

    Anyone know how to do this?
    -----------------------------------
    AmeriWeb Hosting
    One Stop Business Solutions
    AmeriWeb Hosting

  2. #2
    Join Date
    May 2009
    Posts
    766

  3. #3
    Join Date
    Aug 2009
    Posts
    476
    Try this one:

    redirectMatch 301 ^(.*)$ http://www.abc.com/456/
    Hosting24.com Web Hosting - First class web hosting services.
    Boxbilling - Complete billing, invoicing and client management system.

  4. #4
    Quote Originally Posted by Hosting24 View Post
    Try this one:

    redirectMatch 301 ^(.*)$ http://www.abc.com/456/
    I tried your suggested code, but it didn't help. What I was already using:
    redirect permanent /123 http://abc.com/456
    directs only when you go to xxx.com/pictures and not xxx.com/pictures/anything.php

    Also tried unsuccessfully:
    redirectMatch 301 ^(123/.*)$ [url]http://www.abc.com/456/
    redirectMatch 301 ^(/123/*.*)$ [url]http://www.abc.com/456/
    redirectMatch 301 ^(123/*.*)$ [url]http://www.abc.com/456/

    I need something to redirect all file inquiries to the new directory.

    Thanks for the suggestion!
    Bob
    -----------------------------------
    AmeriWeb Hosting
    One Stop Business Solutions
    AmeriWeb Hosting

  5. #5
    Join Date
    May 2009
    Posts
    766
    You're not referencing the captured value in the redirect url:

    RedirectMatch ^/123/(.*)$ [url]http://www.abc.com/456/$1

    Notice that $1 will contain everything in parentheses in the regex, so you don't want (123/.*) or you'll end up with:

    http://www.abc.com/456/123/file.html
    Last edited by mattle; 10-05-2009 at 10:58 AM.

  6. #6
    Join Date
    May 2008
    Location
    Indore, India
    Posts
    1,541
    If you have cPanel, you can easily do that by creating a wild card redirect.

  7. #7
    Join Date
    Mar 2005
    Location
    USA
    Posts
    519
    You can also simply do a one line permanent redirect if you have simply renamed the folder and/or moved the files:

    redirect 301 /123/ http://www.abc.com/456/

  8. #8
    Join Date
    May 2009
    Posts
    766
    Quote Originally Posted by robertk1 View Post
    What I was already using:
    redirect permanent /123 http://abc.com/456
    directs only when you go to xxx.com/pictures and not xxx.com/pictures/anything.php
    Quote Originally Posted by tcstatic
    You can also simply do a one line permanent redirect if you have simply renamed the folder and/or moved the files:

    redirect 301 /123/ http://www.abc.com/456/
    Please read the entire thread before responding...

  9. #9
    Join Date
    Mar 2005
    Location
    USA
    Posts
    519
    Please read the entire thread before responding...
    Uhm.. I did. Unless I'm missing something you simply moved all files or renamed the directory/folder? Am I wrong?

    The one line that I gave will redirect everything like /123/index.html or /123/myfile.php or /123/whatever.jpg all to the same file name at the new location (456) as long as the file name is the same. Am I missing something here as I thought that is what you wanted?

Similar Threads

  1. Help with .htaccess redirect
    By caffeine_man in forum Programming Discussion
    Replies: 4
    Last Post: 04-20-2009, 09:07 PM
  2. .htaccess redirect ?
    By map007 in forum Hosting Security and Technology
    Replies: 8
    Last Post: 12-16-2008, 01:17 PM
  3. 301 redirect with htaccess directory to file?
    By lexington in forum Programming Discussion
    Replies: 1
    Last Post: 05-25-2008, 01:50 AM
  4. via ssh i would like to zip an entire directory, but how?
    By BillyT in forum Programming Discussion
    Replies: 5
    Last Post: 09-04-2006, 08:14 PM
  5. Replies: 7
    Last Post: 09-29-2003, 01:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •