2

htaccess has always given my problems. Every time I think I understand it, htaccess goes against what I just thought I understood. Any help would be GREATLY appreciated.

What I want to do with htaccess is redirect URI's like:

www.example.com/get/something to  www.example.com/get.php/something
www.example.com/cape/something  to www.example.com/active.php/something

Along with a bunch of others. I have that working great, the thing I don't have working is if none of those rules are satisfied then to redirect to my main domain. So if I end up with a URI of www.example.com/anythingThatIsNotDefined/anything or just www.example.com/anythingThatIsNotDefined I want to redirect that to http://www.anotherexample.com

It is that last part I can not get to work. My current htaccess file is:

RewriteEngine On
RewriteRule ^get/(.*)$ /get.php/$1 [L]
RewriteRule ^skin/(.*)$ /active.php/$1 [L]
RewriteRule ^cape/(.*)$ /active.php/$1 [L]

What do I need to modify to get anything that is not get or skin or cape to redirect to my other domain?

I will need to add more than get, skin, and cape in but once I get it working I should be able to add more in easily

Thanks in advance, this has really been stumping me.

(If this is not the right stack site I apologize, it was a 50/50 toss up between here and overflow. I was not sure which one it belonged on.)

1 Answers1

6

.htaccess uses order to determine what happens first (as do all Apache config files). In your case, you simply need to place all of your "special" rewrite rules before a catch-all rule like the one below.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://www.otherdomain.com/$1 [R=301,L]

This rule basically says that for anything which doesn't exist as a hard resource (file or directory), redirect the request to http://www.otherdomain.com, including the URI string. Assuming this comes after your friendly-URL redirects, they won't be caught.

Garrett
  • 4,217
  • 1
  • 24
  • 33