Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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: to  to

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 or just I want to redirect that to

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.)

share|improve this question
up vote 3 down vote accepted

.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 ^(.*)$$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, including the URI string. Assuming this comes after your friendly-URL redirects, they won't be caught.

share|improve this answer
Thank you, that worked. If I wanted to not allow any resources to be accessed (besides the ones I specify) could I just get rid of the conditions? Edit: I tested it without the conditions and that works perfectly for what I needed. Is there any reason either condition should be kept if I want to disallow anything that was not specified? Or was removing both the correct thing to do there? – Ryan Sullivan Mar 22 '12 at 21:25
Yes and no. Read this page for more info on this concept: – Garrett Mar 22 '12 at 22:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .