2016-05-10 10 views
2

ich alte Domain auf neue Domain zu umleiten versuchen aber verlassen nicht-www Homepage, robots.txt und eine einzelne Datei (myfile.html) hinter. Hier ist, was ich.htaccess alte Domain auf neue Domain umleiten aber ausschließen Nicht-www-Version, robots.txt und eine Datei

all www.olddomain.com > all www.newdomain.com 
olddomain.com > 404 error 
olddomain.com/robots.txt > olddomain.com/robots.txt 
olddomain.com/myfile.html > olddomain.com/myfile.html 

hier zu tun versuche, ist, was ich unten versucht:

RewriteEngine on 
RewriteCond %{HTTP_HOST} !^www\. 
RewriteCond %{REQUEST_URI} !/(myfile\.html|robots\.txt) [NC] 
RewriteRule ^$ http://olddomanin.com [R=410,L] 
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L] 

Aus irgendeinem Grund ist es nicht richtig funktioniert.

Antwort

1

Setzen Sie den folgenden Code an der Wurzel .htaccess Datei:

RewriteEngine on 

RewriteCond %{HTTP_HOST} !^www\. 
RewriteCond %{REQUEST_URI} !/(myfile\.html|robots\.txt) [NC] 
RewriteRule ^(.*)$ /$1 [R=404,L] 

# above code will capture any request not having www except myfile.html & 
# robots.txt and directed to 404 error page and if you want 410 change it 

RewriteCond %{REQUEST_URI} !/(myfile\.html|robots\.txt) [NC] 
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L] 

# the above code will capture every request that passed the above rule 
# except myfile.html & robots.txt and redirected it to a new domain 
Verwandte Themen