redirect using .htaccess not working

主宰稳场 提交于 2020-01-24 21:14:30

问题


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

Redirect 301 / https://newsite.com

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

My .htaccess file is located in oldfolder

What am I doing wrong?


回答1:


That is because that is the default behavior of Redirect.

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

You need to use RedirectMatch or RewriteRule.

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

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


来源:https://stackoverflow.com/questions/39004548/redirect-using-htaccess-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!