Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    redirect pages to www using javascript

    Hi,
    I want to redirect pages e,g 'http://mydomain.com/pagename.html' to 'http://www.mydomain.com/pagename.html",i.e if anyone access without www then it will be added automatically,how can i do this using javascript?
    plz help
    Thanks

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,853
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    how can i do this using javascript?
    It need to be carried out by server's configuration settings. You can't "do" it using javascript, because it's purely a client-side language
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    It need to be carried out by server's configuration settings. You can't "do" it using javascript, because it's purely a client-side language
    Yes u r right but i cant use .htaccess bcoz mod_rewrite is not enable on server,therefor i want to do it using javascript,is it possible ?
    Thanks

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,010
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    As abduraooft has said, it is not possible with Javascript.

  • #5
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    As abduraooft has said, it is not possible with Javascript.
    It is possible,after some googling i have found the solution and its working great,following is the code i have used,

    <!--
    enURL = document.URL;

    if(enURL.indexOf("www") == -1 )
    {
    location.href = enURL.replace("http://", "http://www.");
    }
    // -->

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,010
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    With most websites, the URLs with and without "www" in them will point to the same site. You cannot add www to the url shown in the address bar but as you say you can redirect to a different site. But that seems rather pointless - why have to different sites in the first place when you can configure the server to point to the same one?
    Last edited by Philip M; 11-29-2010 at 02:33 PM.

  • #7
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    With most websites, the URLs with and without "www" in them will point to the same site. You cannot add www to the url shown in the address bar but as you say you can redirect to a different site. But that seems rather pointless - why have to different sites in the first place when you can configure the server to point to the same one?
    yes i have suggested this to my client,but he want me to do this without server control panel access,that's y i did it using javascript.

  • #8
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks,i have found solution from http://phproots.com


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •