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:

http://url.com/85344

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 (url.com/NUMBER) to be forwarded to another domain intact (maintaining its directory structure).

So that:

 http://url.com  is redirected to http://www.newurl.com

and

http://url.com/about  is redirected to http://www.newurl.com/about

and so on... but only if it does not match the url.com/83948 type format.

Is that possible?

Thanks, Chris
Avatar of arnold
arnold
Flag of United States of America image

Add a fall through rule below the existing one.
Redirect ^(.*)$ http://www.newurl.com/$1
Or
RewriteRule ^(.*)$ http://www.newurl.com/$1 [r=301,L]
ASKER CERTIFIED SOLUTION
Avatar of arober11
arober11
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
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

ASKER

Thank you both very much.

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

Appreciate it very much!

Chris