问题
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