htaccess - redirecting if no match

Ok, currently in my .htaccess file I have:

RewriteEngine on
RewriteRule ^([0-9]+)$ index.php?p=$1 [L]

It's designed so that if something like this comes in:

it will take that number, assign it to $p, and then run it through index.php so I can process it.

That works great and I need to keep that process.

Now.... what I would like to do is have any url that does not match that format ( to be forwarded to another domain intact (maintaining its directory structure).

So that:  is redirected to

and  is redirected to

and so on... but only if it does not match the type format.

Is that possible?

Thanks, Chris
Who is Participating?
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.

Add a fall through rule below the existing one.
Redirect ^(.*)$$1
RewriteRule ^(.*)$$1 [r=301,L]
To permit index.php to be accessed and to offer a very slightly more efficiently solution, using %{REQUEST_URI} to avoid the slightly less efficient regexp logic above, you could use:

RewriteEngine on
RewriteRule ^([0-9]+)$ index.php?p=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .*{REQUEST_URI} [L,R=301]

Open in new window


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
St_Aug_Beach_BumAuthor Commented:
Thank you both very much.

I tested both of these and this is the one that worked out.

Appreciate it very 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
Apache Web Server

From novice to tech pro — start learning today.