I have tried some several possibilities to redirect only my root domain but unfortunatly i cant get it to work. These are the options that i have tried.
RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com [NC]
RewriteRule ^/?$ http://newsite.com/folder/ [L,R=301]
Also tried this one:
RewriteCond %{HTTP_HOST} ^oldsite.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.oldsite.com [NC]
RewriteRule ^(.*)$ http://newsite.com/folder/$1 [L,R=301]
Both codes redirect all my subpages for example: http://website.com/contact.html
Can anyone advise me what i might be doing wrong or missing anything.
Greets, Roy
try this :
RewriteCond %{HTTP_HOST} oldsite\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
Rewriterule ^(.*)$ http://newsite.com/ [L,R=301]
this will only redirect oldsite.com
to newsite.com
and not do anything for oldsite.com/abc
No need to use mod_redirect, you can just use
RedirectMatch "^/?$" " http://newsite.com "
in a VirtualHost
for oldsite.com
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.