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?
 
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...
0
 
CEHJCommented:
For the address string 's' above try
final String SCHEME = "http://";
String newS = new URI(SCHEME + s).getPath();

Open in new window

0
 
hax1Commented:
oh and the .htaccess file is a simple text file, nothing fancy.
0
 
CEHJCommented:
I assume, since you've posted in the Java TA, you want a Java answer. If that's not the case, please say
0
 
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

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.