使用.htaccess重定向不起作用 [英] redirect using .htaccess not working

查看:147
本文介绍了使用.htaccess重定向不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用.htaccess使用以下代码从子文件夹重定向到另一个域:

I'm trying to redirect using .htaccess from a subfolder to another domain using the following code:

Redirect 301 / https://newsite.com

子文件夹名称为 oldfolder
单击 http://website.com/oldfoler 时,我将重定向到 https:// newsite。 com / oldfolder 。当我点击 http://website.com/oldfoler/about-us 时,我被重定向到 https://newsite.com/ oldfolder / about-us

Subfolder name is oldfolder When I click http://website.com/oldfoler, I'm redirectd to https://newsite.com/oldfolder. When I click on http://website.com/oldfoler/about-us, I'm redirected to https://newsite.com/oldfolder/about-us

我的.htaccess文件位于 oldfolder

My .htaccess file is located in oldfolder

我在做什么错了?

推荐答案

那是因为重定向的默认行为。


然后,任何以URL-Path开头的请求都将返回在目标URL位置向客户端的重定向
请求。除匹配的URL-Path之外的其他
路径信息将附加到
目标URL。

Then any request beginning with URL-Path will return a redirect request to the client at the location of the target URL. Additional path information beyond the matched URL-Path will be appended to the target URL.

https://httpd.apache.org/docs/current/mod/mod_alias.html #redirect

您需要使用 RedirectMatch RewriteRule

因此,如果您要将 / oldfolder 重定向到新域,可以执行此操作。

So if you want to redirect /oldfolder to new domain you can do this.

RedirectMatch 301 ^/oldfolder/? http://newsite.com/

这篇关于使用.htaccess重定向不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆