Redirect
is a mod_alias directive (nothing to do with RewriteEngine
). RewriteRule
belongs to mod_rewrite. mod_rewrite is always processed first, despite the apparent order of the directives in the config file. Consequently you should not mix redirects from both modules as you can get unexpected results, due to the order of processing.
You either need to use mod_rewrite for everything. For example:
RewriteEngine on
# Redirect specific pages
RewriteRule ^audi$ https://www.newdomain.de/cars/audi [R=301,L]
# Redirect everything else
RewriteRule ^ http://www.newdomain.de/ [R=301,L]
You can combine the /audi
and /bmw
redirects in a single directive. For example:
RewriteRule ^(audi|bmw)$ https://www.newdomain.de/cars/$1 [R=301,L]
Where $1
is a backreference to the captured group in the RewriteRule
pattern.
OR, use mod_alias for everything (providing there are no other conflicts). For example:
# Redirect specific pages
Redirect 301 /audi https://www.newdomain.de/cars/audi
# Redirect everything else
RedirectMatch 301 ^/ http://www.newdomain.de/
I removed the slash suffice on the target URL as it's not present in your example.
Note that we need to use RedirectMatch
(also a mod_alias directive) for the "everything else" redirect since Redirect
is prefix-matching and would otherwise redirect to the same URL at the target (not the homepage).
As noted above, Redirect
is prefix-matching, so the first Redirect
directive would actually redirect /audi/something
to /cars/audi/something
. If that is an issue then use RedirectMatch
instead.
You should test first with 302 (temporary) redirects to avoid potential caching issues and you will need to clear your browser (and any intermediary) caches before testing, since the erroneous redirect to the homepage will likely have been cached by the browser.
Aside: Note that mass redirects to the homepage are likely seen as soft-404s by the search engines (notably Google). It is often preferable (for search engines and users) to serve a more meaningful custom 404 with additional links to pages you want to promote.
Reference: