: Htaccess - redirect whole website to another with exact extentions but rediret directory/pages to different directory under different domain I need to redirect whole website from one domain to
I need to redirect whole website from one domain to another with the exact extention, BUT only all pages in specific directory should be redirected to another directory on new website. www.website.com/dir/page-123 (all pages starting with "page-*" to www.newwebsite/dir/. Tried many options, nothing works.
Tried:
RewriteRule ^dir/(.+?)(-[0-9]+)?$ oldwebsite.com/dir
RewriteRule (.*) newwebsite.com/ [R=301,L]
More posts by @RJPawlick198
1 Comments
Sorted by latest first Latest Oldest Best
RewriteRule ^dir/(.+?)(-[0-9]+)?$ oldwebsite.com/dir
RewriteRule (.*) newwebsite.com/ [R=301,L]
Not sure what you thought these directives were doing, or why you were using two directives and rewritting to the oldwebsite in the first one?
If you need to redirect to a different host, then you must specify an absolute URL, including the scheme, in the substitution. eg. newwebsite.com/.
But the last rule takes control on first one
Yes, it would, since you don't include the L (LAST) flag on the first RewriteRule and the second rule matches everything. RewriteRule directives chain together (the output of the first directive is used as the input for the second, etc.), so you need to stop that from happening.
However, you presumably need these to be external Redirects, not internal rewrites.
Try the following in the .htaccess file in the specific subdirectory of oldwebsite.com that you want to redirect from (eg. example.com/dir/.htaccess).
RewriteEngine On
RewriteRule ^(page-.*) newwebsite.com/newdir/ [R=301,L]
This redirects all pages that start with "page-" in the subdirectory (eg. dir) to newwebsite.com/newdir/.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.