• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4543
  • Last Modified:

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
0
bakum
Asked:
bakum
  • 9
  • 5
  • 4
2 Solutions
 
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 :)
0
 
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.
0
 
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.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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/
0
 
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!
0
 
TomeeboyCommented:
Try:

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

Redirect 301 http://www.abc.com/
0
 
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.
0
 
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 :)
0
 
rangasumanCommented:
RewriteEngine on
RewriteRule (.*) http://www.yoursite.com/
If you have your Rewrite module installed.
0
 
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

0
 
bakumAuthor Commented:
also, upping the points as this seems like a harder question than I thought.
0
 
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).
0
 
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.
0
 
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

0
 
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]
0
 
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.
0
 
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!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 9
  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now