Results 1 to 9 of 9
-
10-04-2009, 10:01 PM #1Web Hosting Evangelist
- Join Date
- Feb 2003
- Posts
- 503
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?
-
10-05-2009, 08:04 AM #2Web Hosting Master
- Join Date
- May 2009
- Posts
- 766
You want mod_rewrite: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
-
10-05-2009, 09:24 AM #3Web Hosting Evangelist
- Join Date
- Aug 2009
- Posts
- 477
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.
-
10-05-2009, 10:49 AM #4Web Hosting Evangelist
- Join Date
- Feb 2003
- Posts
- 503
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
-
10-05-2009, 10:51 AM #5Web Hosting Master
- 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.htmlLast edited by mattle; 10-05-2009 at 10:58 AM.
-
10-05-2009, 12:11 PM #6Web Hosting Master
- Join Date
- May 2008
- Location
- Indore, India
- Posts
- 1,723
If you have cPanel, you can easily do that by creating a wild card redirect.
-
10-05-2009, 01:05 PM #7Web Hosting Evangelist
- Join Date
- Mar 2005
- Location
- USA
- Posts
- 523
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/
-
10-05-2009, 01:42 PM #8Web Hosting Master
- Join Date
- May 2009
- Posts
- 766
-
10-05-2009, 02:18 PM #9Web Hosting Evangelist
- Join Date
- Mar 2005
- Location
- USA
- Posts
- 523
Please read the entire thread before responding...
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
-
Help with .htaccess redirect
By caffeine_man in forum Programming DiscussionReplies: 4Last Post: 04-20-2009, 09:07 PM -
.htaccess redirect ?
By map007 in forum Hosting Security and TechnologyReplies: 8Last Post: 12-16-2008, 01:17 PM -
301 redirect with htaccess directory to file?
By lexington in forum Programming DiscussionReplies: 1Last Post: 05-25-2008, 01:50 AM -
via ssh i would like to zip an entire directory, but how?
By BillyT in forum Programming DiscussionReplies: 5Last Post: 09-04-2006, 08:14 PM -
Redirect files from a directory using capital letters to a correspondant directory...
By Bonjour in forum Hosting Security and TechnologyReplies: 7Last Post: 09-29-2003, 01:46 PM