Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-29-2010, 09:02 AM   PM User | #1
shaam
New to the CF scene

 
Join Date: Nov 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
shaam is an unknown quantity at this point
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
shaam is offline   Reply With Quote
Old 11-29-2010, 10:32 AM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,689
Thanks: 158
Thanked 2,184 Times in 2,171 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Quote:
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
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 11-29-2010, 10:40 AM   PM User | #3
shaam
New to the CF scene

 
Join Date: Nov 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
shaam is an unknown quantity at this point
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
shaam is offline   Reply With Quote
Old 11-29-2010, 11:05 AM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,103
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
As abduraooft has said, it is not possible with Javascript.
Philip M is offline   Reply With Quote
Old 11-29-2010, 12:20 PM   PM User | #5
shaam
New to the CF scene

 
Join Date: Nov 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
shaam is an unknown quantity at this point
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.");
}
// -->
shaam is offline   Reply With Quote
Old 11-29-2010, 01:17 PM   PM User | #6
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,103
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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..
Philip M is offline   Reply With Quote
Old 11-30-2010, 12:53 PM   PM User | #7
shaam
New to the CF scene

 
Join Date: Nov 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
shaam is an unknown quantity at this point
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.
shaam is offline   Reply With Quote
Old 05-01-2012, 12:27 PM   PM User | #8
shaam
New to the CF scene

 
Join Date: Nov 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
shaam is an unknown quantity at this point
Thanks,i have found solution from http://phproots.com
shaam is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:44 PM.


Advertisement
Log in to turn off these ads.