1
votes

Can someone help me with url redirect/rewrite?

  1. example.com/url/* --> newdomain.com/new/path/url/* not showing the forwarded url
  2. example.com/* --> newdomain.com/new/path/to/go/* not showing the forwarded url
  3. example.com --> newdomain.com showing forwarded url

I've tried RedirectMatch or Rewirite Rules in the VHost file...

  1. RedirectMatch ^/url/(.*)$ http://newdomain.com/new/path/url/url/$1
  2. RedirectMatch ^/(.*)$ http://newdomain.com/new/path/go/$1
  3. RewriteEngine on RewriteCond %{HTTP_HOST} ^example.com$ RewriteRule ^(.*)$ http://newdomain.com/$1

Thanks for help!!

1

1 Answers

0
votes

To surpress the forwarded URL use [P] as Parameter and use rewrites instead of redirects, for the startpage use R=301 to permanentely rewrite to new domain:

if really needed (in case of both domains hosted on one server without vhost) put this in front:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^example.com$
RewriteRule .? - [S=3]
RewriteRule  ^/$ http://newdomain.com/ [R=301,L]
RewriteRule  ^/url/(.*)$ http://newdomain.com/new/path/url/$1 [P,L]
RewriteRule  ^/(.*)$ http://newdomain.com/new/path/to/go/$1 [P,L]

Let us know if it works as intended and if not, what went wrong :)


UPDATE

Put this in LoadModule conf:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

And this where your rewrite etc. are:

RewriteEngine On

RewriteCond %{HTTP_HOST} example.com$
RewriteRule  ^/$ http://newdomain.com/ [R=301,L]

ProxyPreserveHost on
ProxyPassMatch  /url/(.+) http://newdomain.com/new/path/url/$1
ProxyPassMatch  /(.+) http://newdomain.com/new/path/to/go/$1
ProxyPassReverse / http://newdomain.com/