Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
481 views
in Technique[技术] by (71.8m points)

.htaccess - WAMP server redirect old domain names to new domain name?

I have WAMP server where there are 5 projects hosted 192.168.0.10 as

192.168.0.10:80
192.168.0.10:81
192.168.0.10:82
192.168.0.10:83
192.168.0.10:84

now I have changed and moved all these projects to new server 192.168.0.11 as

192.168.0.11:80
192.168.0.11:81
192.168.0.11:82
192.168.0.11:83
192.168.0.11:84

I want if someone still access 192.168.0.10:80/* it should be redirected to 192.168.0.11:80/*

what will be best solution? for time being I can keep old server and place there some file e.g. .htaccess for redirection

I tried below in .htaccess file at old server but still it is not redirecting

<IfModule mod_rewrite.c>
   RewriteEngine on 
   RewriteRule ^$ app/webroot/ [L]
   RewriteRule (.*) app/webroot/$1 [L]

   #code below is for redirtect
   RewriteEngine On
   RewriteCond %{HTTP_HOST} ^192.168.0.10$
   RewriteRule ^(.*)$ http://192.168.0.11$1 [R=301,L]
</IfModule>
question from:https://stackoverflow.com/questions/65901037/wamp-server-redirect-old-domain-names-to-new-domain-name

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

With your shown samples, could you please try following. Please make sure to place these rules always at top of your htaccess file. Values and etc are totally based on shown samples by original poster here.

RewriteEngine ON
RewriteCond %{HTTP_HOST} ^192.168.0.10:81$
RewriteRule ^ http://192.168.0.11:%{SERVER_PORT}%{REQUEST_URI} [NE,R=301,L]

NOTE: As per OP's suggestion, edited line with port 81 here in condition line.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...