• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 234
  • Last Modified:

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]
0
awarraic
Asked:
awarraic
  • 2
  • 2
2 Solutions
 
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:
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
 
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now