htaccess redirect wildcard

Hi, little confused on how wildcards work in htaccess redirects....

redirect 301 /abcmag/*.* http://www.abc.com

how do I represent the *.*?  Also, does that *.* work for subdirectories to?  Like /abcmag/dir1/index.php AND /abcmag/dir2/testing.php ?  I want it to redirect everything from /abcmag on down to the new address.

thanks!

-mb
bakumAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TomeeboyCommented:
Try something like this in the htaccess in your abcmag folder:

RewriteEngine ON
RewriteRule ^(.*)$ http://www.abc.com/$1 [R=301,L]

Should map everything to your new site, so if somebody tries to access /abcmag/dir1/index.php, it will send them to http://www.abc.com/dir1/index.php.

Hope that helps :)
TomeeboyCommented:
Sorry, forgot to mention that the above example may not work if your server doesn't have mod_rewrite enabled in Apache.  This is usually turned on, but I don't know what kind of server/hosting you have.  There's a chance it may not work for you.
rangasumanCommented:
Redirect /olddirectory http://yoursite.com/newdirectory/
This will redirect everything inside the olddirectory to your new directory. So, if you are using
Redirect /olddirectory http://yoursite.com/
Then http://youroldsite.com/olddirectory/dir1 will now be http://yoursite.com/dir1
and http://youroldsite.com/olddirecoty/dir2 will now be http://yoursite.com/dir2 and so on.
You do not need to use *.* It is already implied if you are not specifying a file name. Hope that helps.
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

TomeeboyCommented:
If it's a permanent move, you NEED to be using a 301 redirect so that search engines realize that it's permanent.  Otherwise, it will send a 302 status code, which means temporary redirect.  So if you're not going to use the mod_rewrite method (or can't use it) then do this:

Redirect 301 /abcmag http://www.abc.com/
bakumAuthor Commented:
OK, we're close...

Redirect /olddirectory http://yoursite.com/   - RIGHT
Then http://youroldsite.com/olddirectory/dir1 will now be http://yoursite.com/dir1 - no, redirect to  http://yoursite.com
and http://youroldsite.com/olddirecoty/dir2 will now be http://yoursite.com/dir2 - ditto

the two servers do not have similar structures (I didn't do it, I just have to clean up after it, if you know what I mean).  So every file and subfolder of olddirectory/ needs to be redirected permanently to http://abc.com with NO matching director structure on the new site.  

Cool?  Thanks guys.  I love this site so much!
TomeeboyCommented:
Try:

Redirect 301 / http://www.abc.com
TomeeboyCommented:
Or, actually, it might be:

Redirect 301 http://www.abc.com/
TomeeboyCommented:
Actually, I'm not sure if you can redirect everything to one page using the standard Redirect 301 method.  I think you may need to use a mod_rewrite method, such as:

RewriteEngine ON
RewriteRule /.* http://www.abc.com/ [R=301,L]

Which should send any requests (regardless of page or directory) to http://www.abc.com.
TomeeboyCommented:
Redirectmatch might work as well (which is not mod_rewrite, in case you can't use that):

redirectmatch permanent (.*) http://www.abc.com/

I think it will still output the 301 code as well using this method.  See which one works best for you and let me know if you still have trouble getting them to work :)
rangasumanCommented:
RewriteEngine on
RewriteRule (.*) http://www.yoursite.com/
If you have your Rewrite module installed.
bakumAuthor Commented:
OK, so I tried this:

RewriteEngine ON
RewriteRule /olddirectory/.* http://www.abc.com/ [R=301,L]

and it's not working.  www.abc.com/olddirectory/blah.php is redirecting to www.abc.com/olddirectory/blah.php, not www.abc.com/(index.php) like I want it to.  Still a little stumped.  

If it means anything this is a Mambo site.  I don't really have much to do with it other than being asked to fix the things that the Mambo guys can't figure out.  Not really earning my pay today I guess.  Anyway, I mention this because there is only one .htaccess file that I know of, which is why I'm puting the directory in the file path.  Don't know if that makes a difference or not.

-mb

bakumAuthor Commented:
also, upping the points as this seems like a harder question than I thought.
TomeeboyCommented:
Did you try putting this in an htaccess file in the document root of the site you are redirecting?

RewriteEngine ON
RewriteRule /.* http://www.abc.com/ [R=301,L]

Try that and don't change anything other than www.abc.com (to whatever the new site is).
rangasumanCommented:
RewriteEngine on
RewriteRule (.*) http://www.yoursite.com/
should be sufficient as I mentioned earlier. Use this inside your document root (the /directory) and then everything in there is redirected to your new website.
bakumAuthor Commented:
RewriteEngine ON
RewriteRule /.* http://www.abc.com/ [R=301,L]

This was so CLOSE!  It works, but it's a Mambo site and it actually redirects all the CSS calls too so the site ends up with no styles (which is bad :) ), which is maybe the product of the redirect being a touch too broad?   I'm still nto sure how these expressions are set up, but to reiterate in English (that is to say, not in code):

I want to redirect www.abc.com/abcmag/*.* (and all possible sub dirs and files) to www.abc.com/index.php.  note just the /abcmag/ dir on down gets the redirect.  BUT, the tricky part is this is a mambo site, and there is no actual /abcmag/ dir to plop an htaccess file in, there is only one htaccess file at the root.  What a pain, huh?

Go experts Go!

-mb

TomeeboyCommented:
What type of files will you be redirecting?  Are they all the same type?  For example .html files or .php files.

I think you could do this:

RewriteEngine ON
RewriteRule /.*html http://www.abc.com/ [R=301,L]

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rangasumanCommented:
Try this code:

RewriteEngine ON
RewriteRule /.* http://www.abc.com/ [R=301,L]
RewriteCond   %{REQUEST_URI}  !^/SomeDir/.*
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|js|css)$

Please change "SomeDir" (code line 3) to any directory you do not want to redirect. You can make copies of that line to accomodate more directories. If you don't have any then you can simply delete that line. Code line 4 will take care of your images, css, javascript files. You can add more extensions by using a | delimiter. They will not be redirected. Hope that helps.
bakumAuthor Commented:
The user's request was cancelled so this issue will remain unsolved.  Anyway, I split the points between the two of you for some great answers and for hanging in there.  Thanks so much!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.