hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Web Hosting Talk Tutorials : Programming Tutorials : index.php redirect
Reply

Forum Jump

index.php redirect

Reply Post New Thread In Programming Tutorials Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 08-28-2006, 05:29 AM
erystiva erystiva is offline
Newbie
 
Join Date: Aug 2006
Posts: 13

index.php redirect


Hi all,

I have a script that is locked to my domain. It is no longer supported and therefore I cannot change this domain lock. The license requires access to the script by having a www in the address not just http

Therefore users trying to access the script without www in the address are displayed an error message. Is there a code I can insert into the index page so if the user accesses it without www in the address it will redirect to the same index page but by including www in the address.

Sorry I cant be more specific, currently im not certified to post urls so its made it a little hard to explain my situation easily.

Im hosted on a windows server so believe I cannot use .htaccess, any help will be greatly appreciated as my php knowledge isnt very good.

Thanks



Sponsored Links
  #2  
Old 08-28-2006, 08:51 AM
Omega-Mark Omega-Mark is offline
Junior Guru
 
Join Date: Jan 2005
Location: Leeds, England
Posts: 183
Welcome to WHT!

all i can suggest is you put an index.html page in there along with it with meta tags in that redirect it to www.

Code:
<html><head><META 
http-equiv="refresh" content="2;URL=http://www.yourdomain.com/index.php"></head><body> <center>If you are not redirected to the site within 2 seconds <a href="http://www.yourdomain.com/index.php">Click Here</a></body></html>
there's the html code for the whole page.

there is also a way to do it via the php script however you haven't posted the source for ti so we can't really help you with something to put in the php script

also this thread should be in the programming discussion forum as it's not a tutorial


Last edited by Omega-Mark; 08-28-2006 at 08:56 AM.
  #3  
Old 08-28-2006, 08:56 AM
layer0 layer0 is offline
Performance Specialist
 
Join Date: Dec 2004
Location: New York, NY
Posts: 10,502
You can also use PHP:

PHP Code:
<?PHP header("Location: http://www.example.com/"); exit ?>

__________________
MediaLayer, LLC - www.medialayer.com Lightning fast web hosting since 2005.
The pioneers of optimized web hosting, featuring LiteSpeed Web Server & SSD Storage
Learn how we can make your website load faster, translating to better conversion rates for your business!

Sponsored Links
  #4  
Old 08-28-2006, 10:12 AM
erystiva erystiva is offline
Newbie
 
Join Date: Aug 2006
Posts: 13
Thanks to the both of you for replying.

This was my first post on this forum and therefore could not post direct links or use the PHP tags, I figured it would be abit messy if I just posted the contents of the index.php straight into the thread post.

Do you just need the first few lines or the whole file (635 lines) ?

A index.html file wouldnt be beneficial really as it wouldn't solve the problem if the user typed in the address but only omitted the www part.

Sorry for posting in the wrong thread, figured programming discussion would be the most likely place, didnt realise I was in the tutorial sub-forum though, could a mod please move this to the relevant location please.

layer0: Do I simply paste that code into the index.php file and enter the location I want it to redirect to?

Thanks again to you both

  #5  
Old 08-28-2006, 11:54 AM
erystiva erystiva is offline
Newbie
 
Join Date: Aug 2006
Posts: 13
I have also posted a support ticket to my webhost, although its strictly not his responsibility to support this kind of question he is a helpful guy and may sort something out for me.

Any other suggestions would be appreciated. The script does call a config file, perhaps a code could be placed in there to avoid looping in the index file.

  #6  
Old 08-29-2006, 12:13 PM
Omega-Mark Omega-Mark is offline
Junior Guru
 
Join Date: Jan 2005
Location: Leeds, England
Posts: 183
Quote:
Originally Posted by erystiva
Thanks to the both of you for replying.

This was my first post on this forum and therefore could not post direct links or use the PHP tags, I figured it would be abit messy if I just posted the contents of the index.php straight into the thread post.

Do you just need the first few lines or the whole file (635 lines) ?

A index.html file wouldnt be beneficial really as it wouldn't solve the problem if the user typed in the address but only omitted the www part.

Sorry for posting in the wrong thread, figured programming discussion would be the most likely place, didnt realise I was in the tutorial sub-forum though, could a mod please move this to the relevant location please.

layer0: Do I simply paste that code into the index.php file and enter the location I want it to redirect to?

Thanks again to you both
just paste the code that layer0 suggested tot he top of your script.

  #7  
Old 09-01-2006, 03:12 AM
erystiva erystiva is offline
Newbie
 
Join Date: Aug 2006
Posts: 13
Thanks for confirming that for me Omega-Mark

  #8  
Old 09-05-2006, 02:38 AM
n3tu n3tu is offline
New Member
 
Join Date: Sep 2006
Posts: 3
.. or you can use .htaccess redirect,
redirect 301

  #9  
Old 09-09-2006, 03:51 AM
frattay22 frattay22 is offline
Web Hosting Master
 
Join Date: Jun 2003
Posts: 629
an htaccess redirect is probably the quickest and easiest way to do that, just add
Redirect / http : / / www dot whatever you want dot com

(obviously take out the spaces in the url)

__________________
TodaysDrops

  #10  
Old 09-09-2006, 03:54 AM
mxdn mxdn is offline
Newbie
 
Join Date: Jan 2006
Posts: 21
Few Suggestions:-
I Report this Bug to Developer of this system rather your hosting company. It is one min job to solve.
II Rename the Main Index.php to anything.php and add this code
[PHP
<?PHP
// filename: index.php
header("Location: http://www.example.com/anything.php");
?>
[/PHP]

  #11  
Old 09-21-2006, 10:04 PM
RACKSET RACKSET is offline
Junior Guru Wannabe
 
Join Date: Jan 2006
Posts: 40
Add code below to top of index.php or config.php file:

PHP Code:

if ($_SERVER['HTTP_HOST']!="www.YourDomain.com") {
 
header("location: http://www.YourDomain.com");


__________________
Website Hosting by Rackset
Professional, Affordable, Reliable

Web Hosting Provider

  #12  
Old 09-22-2006, 05:12 AM
kids kids is offline
Newbie
 
Join Date: Jul 2006
Posts: 19
Oh

Quote:
Originally Posted by RACKSET
Add code below to top of index.php or config.php file:

PHP Code:

if ($_SERVER['HTTP_HOST']!="www.YourDomain.com") {
 
header("location: http://www.YourDomain.com");

If we use upper script for this:

PHP Code:
 if ($_SERVER['HTTP_HOST']="www.sub-domain.YourDomain.com") {
 
header("location: http://www.YourDomain.com/sub-domain/");

Can you tell me "it will run"?

__________________
<< Please see the Rules page for signature limitations. >>

  #13  
Old 09-22-2006, 08:53 AM
RACKSET RACKSET is offline
Junior Guru Wannabe
 
Join Date: Jan 2006
Posts: 40
I have not tested that, but you can check it and please send the result.

__________________
Website Hosting by Rackset
Professional, Affordable, Reliable

Web Hosting Provider

  #14  
Old 11-12-2006, 11:36 PM
horizon horizon is offline
Web Hosting Master
 
Join Date: Mar 2006
Posts: 961
http://ca3.php.net/preg_match

Example 3 is also a very good test result.

  #15  
Old 12-29-2006, 02:25 PM
horizon horizon is offline
Web Hosting Master
 
Join Date: Mar 2006
Posts: 961
Further to what I stated above,

I would change:

PHP Code:
if ($_SERVER['HTTP_HOST']="www.sub-domain.YourDomain.com") {
 
header("location: http://www.YourDomain.com/sub-domain/");

for:

PHP Code:
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") {
 
header("location: https://www.YourDomain.com/sub-domain/");
 } else {
 
header("location: http://www.YourDomain.com/sub-domain/");


Reply

Related posts from TheWhir.com
Title Type Date Posted
ServInt Listing 2014-01-07 17:41:21
ServInt Listing 2014-01-07 17:41:21
US, Asia Bring Most Near-Term Ecommerce Opportunity: Forrester Web Hosting News 2013-09-20 14:31:39
Yahoo Site Visits Surpass Google for First Time Since 2011: comScore Report Web Hosting News 2013-08-22 16:01:33
Technology Convergence Conference 2013 Web Hosting Events 2013-01-31 19:51:20


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

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 Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?