Link to home
Start Free TrialLog in
Avatar of Chris Andrews
Chris AndrewsFlag for United States of America

asked on

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
Avatar of arnold
Flag of United States of America image

Add a fall through rule below the existing one.
Redirect ^(.*)$$1
RewriteRule ^(.*)$$1 [r=301,L]
Avatar of arober11
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Chris Andrews


Thank you both very much.

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

Appreciate it very much!