URL re-write

Hi, I am trying to re-direct a url to a totally different domain name but want to keep the query string or any left over url the same. So, basically, just change the domain name, nothing else...
Thanks much.

old url:
www.abc.com/febs/[random document name, for example xyz.pdf]

to:
www.def.com/febs/[random document name, for example xyz.pdf]
awarraicAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
For the address string 's' above try
final String SCHEME = "http://";
String newS = new URI(SCHEME + s).getPath();

Open in new window

hax1Commented:
create a .htaccess file in abc.com/febs/

and copy the following in it:

RewriteEngine on
RewriteRule   ^(.*)$  http://www.def.com/febs/$1 [R]



this keeps everything intact so f.e. http://abc.com/febs/test.php?action=do&test=test
would be redirected to http://www.def.com/febs/test.php?action=do&test=test

that's it ...

if you want to redirect the entire domain remove the /febs/ and copy the .htaccess file in the root dir of abc.com...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hax1Commented:
oh and the .htaccess file is a simple text file, nothing fancy.
CEHJCommented:
I assume, since you've posted in the Java TA, you want a Java answer. If that's not the case, please say
for_yanCommented:
 public class RewriteUrl {

    public static URL reWriteUrl(URL url){
            URL newUrl = null;

        try{

        String sUrl = url.toString();
        sUrl= sUrl.replace("//www.abc.com/febs","//www.def.com/febs");

      newUrl = new URL(sUrl);


   }
   catch (Exception ex){

       ex.printStackTrace();
   }

        return newUrl;

    }


    public static void main(String[] args) {



         try{

    URL url= new URL("http://www.abc.com/febs/Software/Server%20Software/Web_Servers/Apache/Q_27379045.html?cid=1576");
             System.out.println(url);

         URL newUrl = reWriteUrl(url);
              System.out.println(newUrl);


    }
    catch (Exception ex){
       ex.printStackTrace();
    }

}

}

}

Open in new window


Output:
http://www.abc.com/febs/Software/Server%20Software/Web_Servers/Apache/Q_27379045.html?cid=1576
http://www.def.com/febs/Software/Server%20Software/Web_Servers/Apache/Q_27379045.html?cid=1576

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.