My url is http://www.abctest.com/mysamples/ . I need to replace this with http://www.abctest.net/mysamples/ . Please let me know how to write a regular expression to match the repeated pattern (www.abctest.com/mysamples) and replace it with http://www.abctest.net/mysamples using RewriteRule.
Asked
Active
Viewed 100 times
-1
-
2Possible duplicate of [Redirect, Change URLs or Redirect HTTP to HTTPS in Apache - Everything You Ever Wanted to Know About Mod\_Rewrite Rules but Were Afraid to Ask](https://serverfault.com/questions/214512/redirect-change-urls-or-redirect-http-to-https-in-apache-everything-you-ever) – Dave M Nov 21 '17 at 13:47
-
1What do you gain by obfuscating the names involved? If you really think the world will end if your names are seen at least use proper names for documentation: example.com and example.net – Patrick Mevzek Nov 21 '17 at 14:48
-
1AFAIK `RewriteRule` is an Apache configuration token, I doubt that IIS will have it, why did you use both tags apache-2.4 and IIS? – Patrick Mevzek Nov 21 '17 at 14:49
1 Answers
0
Did you look at Apache documentation? It has your exact use case here: http://httpd.apache.org/docs/2.4/rewrite/remapping.html#canonicalhost
RewriteCond "%{HTTP_HOST}" "!^www\.example\.com" [NC]
RewriteCond "%{HTTP_HOST}" "!^$"
RewriteRule "^/?(.*)" "http://www.example.com/$1" [L,R,NE]
Patrick Mevzek
- 9,273
- 7
- 29
- 42