简体   繁体   English

(Wordpress).htaccess选择性重定向

[英](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 www.oldsite.it - > http://newsite.it

and

www.oldsite.it/whatever --> http://newsite.it/search?q=whatever 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 谢谢

You need 2 conditional rules here to redirect the old homepage and old urls to the new location ,try : 您需要在此处使用2个条件规则将旧主页和旧网址重定向到新位置,请尝试:

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. 要使重定向成为永久性,请在确定规则有效时将R更改为R = 301。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM