(WordPress) .htaccess Selective Redirect

I want to redirect the home of my old site to the home of my new site, while I want every subpage to redirect to the page search of the new site.
Briefly:

www.oldsite.it –> http://newsite.it

Read More

and

www.oldsite.it/whatever –> http://newsite.it/search?q=whatever

I want the conditions to live both and strictly.
I achieved to let them work but separately.
Here’s my code:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} oldsite.it/$ 
RewriteRule ^(.*)$ http://newsite.it/search?q=$1 [R=301,L]

RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]
</IfModule>

How can I make them work?
Thanks

Related posts

1 comment

  1. You need 2 conditional rules here to redirect the old homepage and old urls to the new location ,try :

    RewriteEngine On
    RewriteBase /
    #1)redirect "oldsite.it" to "newsite.it#
    RewriteCond %{HTTP_HOST} ^(www.)?oldsite.it$ 
    RewriteRule ^$ http://newsite.it [NC,L,R]    
    #2)redirect "oldsite.it/foobar" to "newsite.it/search?q=foobar#
    RewriteCond %{HTTP_HOST} ^(www.)?oldsite.it$ 
    RewriteRule ^(.+)$ http://newsite.it/search?q=$1 [QSA,NC,R,L]
    

    Clear your browser’s cache before testing these rules.

    To make the redirect permanent ,change R to R=301 in both rules when you are sure the rules are working.

Comments are closed.