Forum Moderators: phranque
Redirect 301 /some-folder/some-page.html https://www.mynewdomain.com/my-new-page.html
[edited by: not2easy at 3:20 am (utc) on Jun 24, 2019]
[edit reason] readability [/edit]
Here is a one line solution, put this as your first redirect before any redirect rules you may already have. These one liners execute first.
RewriteRule ^some-folder/some-page\.html$ https://www.mynewdomain.com/my-new-page.html [R=301,L] The use of RewriteRule to perform this task may be appropriate if there are other RewriteRule directives in the same scope. This is because, when there are Redirect and RewriteRule directives in the same scope, the RewriteRule directives will run first, regardless of the order of appearance in the configuration file.
Here is the redirect for moving the whole site:That rule sends every request for an URL containing "some-page/" to the root URL of the other domain so you can see why only one page would be the one you intended to land there. To send each page to it's own replacement (new) page you need to capture the requested page and add that on to the request again. Your rule is not capturing the entire request, it is simply rewriting all requests containing "some-page/" to the new domain's root.
RewriteRule ^some-page/$ http://www.example.com/ [R=301,L]
http://www.example.com/some-page.html (this is the correct url)Is there an actual "some-page.html" on the new domain - or is that old "some-page.html" now the index.html page in the root of the new domain? The header checker results say that page is not found on the new domain.
Redirect 301KnowOne, you have stumbled into a long-running quarrel in the Apache subforum. Short version:
RewriteRule ^some-page/$ http://www.example.com/ [R=301,L] would need to capture the name of the page in order for it to send visitors to that page rather than the root, but it depends on what else you have in the htaccess file. RewriteRule ^some-page/?$ http://www.example.com/$1 [R=301,L] would capture the page requested and add it to the end. ... a 404 on the original domain any time anyone tries to access one of those pages on the old site.it is because of 2 things: the old page is not there any more and because the request is coming before the rewrite rule. If the request was hitting the rewrite rule before hitting the canonical rewrite, it would never see that the old page is not there any more.