RewriteRule ^dir/(.+?)(-[0-9]+)?$ oldwebsite.com/dir
RewriteRule (.*) newwebsite.com/$1 [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. http://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 R
edirects, 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-.*) http://newwebsite.com/newdir/ [R=301,L]
This redirects all pages that start with "page-" in the subdirectory (eg. dir
) to http://newwebsite.com/newdir/
.