htaccess redirect old links to new domain

I changed my site domain, and want to redirect old urls to new domain

(note: instead of numbers 93, 54 maybe any digit number exists) the old urls are:

http://olddomain.com/
http://olddomain.com/45
http://olddomain.com/p/93

the new urls are:

http://newdomain.com/
http://newdomain.com/45
http://newdomain.com/p/93

I tried this at htaccess:

RewriteEngine on

RewriteCond %{REQUEST_URI} 
RewriteRule  http://newdomain.com/

RewriteCond %{REQUEST_URI} (\d+)/
RewriteRule (\d+)/ http://newdomain.com/$1

RewriteCond %{REQUEST_URI} p/(\d+)/
RewriteRule p/(\d+)/ http://newdomain.com/p/$1

but not worked :(

In addition, there is a choice at cpanel caller Redirects can I redirect the old links to new by using it. thanks for help

Answers


This should work:

RewriteEngine On
RewriteRule ^(.*) http://newdomain.com/$1 [R=301]

It will redirect all pages from the old website to the new website.


If it's just those three you want to redirect, you can do it with an OR in your regex. The below should work.

RewriteEngine On
RewriteRule ^/(45|p/93|$)$ http://newdomain.com/$1 [R,L]

Need Your Help

"Facade" terminology question

design-patterns soa uml

I have terminology/modeling question about representing components in a service. Consider..

Cant set image for UIBarButtonItem

ios objective-c iphone uitableview uibarbuttonitem

I'm trying to set image for my UIBarButtonItem and I can't manage to do that. I tried two times, and in first case I get my image in right place, but when I click on button nothing happens (it shou...