[英].htaccess - redirect, if a specific url match
I need to redirect users to a new domain, but I need that in case a user visits a particular URL, then he/she needs to be redirected to another URL.我需要将用户重定向到一个新域,但我需要这样做,以防用户访问特定 URL,然后他/她需要重定向到另一个 URL。
Let me clarify...让我澄清...
If the user visits http://oldexample.com/postvendita/
I need to redirect them to http://newexample.com/assistenza
如果用户访问
http://oldexample.com/postvendita/
我需要将他们重定向到http://newexample.com/assistenza
Otherwise, for every other URL http://oldexample.com/*
I need to redirect them to http://newexample.com/new-page
否则,对于每个其他 URL
http://oldexample.com/*
我需要将它们重定向到http://newexample.com/new-page
Here is my attempt:这是我的尝试:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)postvendita(.*)$ http://www.newexample.com/assistenza [L,R=301]
RewriteCond %{HTTP_HOST} !^oldexample\.com$ [NC]
RewriteRule ^(.*)$ http://www.newexample.com/new-page [R=301,L]
Now if I visit any of the old pages, I will be redirected to http://www.newexample.com/new-page
, so the first rule doesn't work, how should I change it?现在如果我访问任何旧页面,我将被重定向到
http://www.newexample.com/new-page
,所以第一条规则不起作用,我应该如何更改它?
To handle this via .htaccess you'll want to match the first one and use a catch-all to redirect everything else:要通过.htaccess处理此问题,您需要匹配第一个并使用 catch-all 重定向其他所有内容:
RewriteEngine On
RewriteRule ^postvendita/?$ http://www.newexample.com/assistenza [R=301,L,NE]
RewriteRule .* http://www.newexample.com/new-page [R=301,L,NE]
A 301 redirect is a permanent redirect which passes between 90-99% of link juice (ranking power) to the redirected page.
301 重定向是永久重定向,它将 90-99% 的链接汁(排名能力)传递到重定向页面。 301 refers to the HTTP status code for this type of redirect.
301 指的是这种重定向的 HTTP 状态代码。 In most instances, the 301 redirect is the best method for implementing redirects on a website.
在大多数情况下,301 重定向是在网站上实现重定向的最佳方法。
Alternatively, if you're not comfortable writing RewriteRules, you can use the following lines:或者,如果您不习惯编写 RewriteRules,您可以使用以下几行:
Redirect 301 /postvendita/ http://www.newexample.com/assistenza
Redirect 301 /postvendita http://www.newexample.com/assistenza
Redirect 301 / http://www.newexample.com/new-page
Or with RedirectMatch :或者使用RedirectMatch :
RedirectMatch 301 /postvendita/? http://www.newexample.com/assistenza
RedirectMatch 301 .* http://www.newexample.com/new-page
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.