0
votes

have some problems with my .htaccess file. I have two domains, old one and new one. i want to redirect user to the new site, when they visit the old domain.

Example: if they visit: "olddomain.com" then they should get redirected to "newdomain.com". this is actually not that hard to code BUT i want some special redirects too. if someone trys to visit "olddomain.com/service.html" then i want redirect the user to "newdomain.com/whatwedo.hml". And if someone trys to visit "olddomain.com/test/hello/text.html" then i want to redirect him to "newdomain.com/something/hello.html".

i have a list of 20 specific links i want to redirect.

what i've tried so far:

RewriteEngine On
RewriteCond %{HTTP_HOST} (www\.)?olddomain.com/service.html 
RewriteRule (.*) http://www.newdomain.com/whatwedo.hml [R=301,L]

RewriteCond %{HTTP_HOST} (www\.)?olddomain.com
RewriteRule (.*) http://www.newdomain.com/ [R=301,L]

with this code every visit on olddomain.com/whatever will redirect to "newdomain.com"

can someone help me?

thank you :)

Greetings

1
Is your newdomain pointing to the same document root as your olddomain?Amit Verma

1 Answers

0
votes

%{HTTP_HOST} will contain only the domain name used in browser address bar (olddomain.com) but not the URI (/service.html), so your first condition will never be matched. Try this:

RewriteCond %{HTTP_HOST} (www\.)?olddomain.com 
RewriteRule ^service\.html http://www.newdomain.com/whatwedo.hml [R=301,L]