Results 1 to 25 of 25
Thread: index.php redirect
-
08-28-2006, 05:29 AM #1Newbie
- Join Date
- Aug 2006
- Posts
- 17
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
-
08-28-2006, 08:51 AM #2Junior Guru
- Join Date
- Jan 2005
- Location
- Leeds, England
- Posts
- 187
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 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 tutorialLast edited by Omega-Mark; 08-28-2006 at 08:56 AM.
-
08-28-2006, 08:56 AM #3Eternal Member
- Join Date
- Dec 2004
- Location
- New York, NY
- Posts
- 10,710
You can also use PHP:
PHP Code:<?PHP header("Location: http://www.example.com/"); exit ?>
MediaLayer, LLC - www.medialayer.com Learn how we can make your website load faster, translating to better conversion rates for your business!
The pioneers of optimized web hosting, featuring LiteSpeed Web Server & SSD Storage - Celebrating 10 Years in Business
-
08-28-2006, 10:12 AM #4Newbie
- Join Date
- Aug 2006
- Posts
- 17
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
-
08-28-2006, 11:54 AM #5Newbie
- Join Date
- Aug 2006
- Posts
- 17
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.
-
08-29-2006, 12:13 PM #6Junior Guru
- Join Date
- Jan 2005
- Location
- Leeds, England
- Posts
- 187
Originally Posted by erystiva
-
09-01-2006, 03:12 AM #7Newbie
- Join Date
- Aug 2006
- Posts
- 17
Thanks for confirming that for me Omega-Mark
-
09-05-2006, 02:38 AM #8Newbie
- Join Date
- Sep 2006
- Posts
- 6
.. or you can use .htaccess redirect,
redirect 301
-
09-09-2006, 03:51 AM #9Web Hosting Master
- Join Date
- Jun 2003
- Posts
- 633
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)
-
09-09-2006, 03:54 AM #10Newbie
- Join Date
- Jan 2006
- Posts
- 25
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]
-
09-21-2006, 10:04 PM #11Junior Guru Wannabe
- Join Date
- Jan 2006
- Posts
- 46
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");
}
-
09-22-2006, 05:12 AM #12Newbie
- Join Date
- Jul 2006
- Posts
- 22
Oh
Originally Posted by RACKSET
PHP Code:if ($_SERVER['HTTP_HOST']="www.sub-domain.YourDomain.com") {
header("location: http://www.YourDomain.com/sub-domain/");
}
<< Please see the Rules page for signature limitations. >>
-
09-22-2006, 08:53 AM #13Junior Guru Wannabe
- Join Date
- Jan 2006
- Posts
- 46
I have not tested that, but you can check it and please send the result.
-
11-12-2006, 11:36 PM #14Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
http://ca3.php.net/preg_match
Example 3 is also a very good test result.
-
12-29-2006, 02:25 PM #15Web Hosting Master
- Join Date
- Mar 2006
- Posts
- 984
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/");
}
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/");
}
-
08-03-2008, 12:07 PM #16Newbie
- Join Date
- Dec 2005
- Posts
- 27
(I know this thread is kinda old, but I think this is an important note for people finding this thread in the future)
What all the above ones have done will indeed redirect the page, however search engines will still see it as a seperate page from the one you're redirecting it to.
Adding this to the end of the "header" function will make sure search engines know to treat it as the same page - which can greatly help with your page rank, backlink count, etc.
, TRUE, 301);
eg:
PHP Code:header("location: [blahblahblah]", TRUE, 301);
-
08-03-2008, 12:35 PM #17Newbie
- Join Date
- Jan 2006
- Posts
- 25
-
08-03-2008, 09:46 PM #18Newbie
- Join Date
- Jul 2006
- Posts
- 22
Oh, my site has been gone this way but I never though it take a good effect like that.
By the way, thank for your informations,<< Please see the Rules page for signature limitations. >>
-
08-25-2009, 12:19 PM #19Disabled
- Join Date
- Aug 2009
- Posts
- 45
I wish to see tutorial for redirection by IP-address (by country) in here..
-
09-19-2009, 05:01 AM #20Newbie
- Join Date
- May 2009
- Posts
- 12
better to use php code
-
07-01-2010, 03:09 PM #21Newbie
- Join Date
- Feb 2008
- Posts
- 10
Good info! htaccess can also be used to redirect pages with 301 redirects. This is the way that I have been doing it recently.
-
07-25-2010, 07:55 PM #22Newbie
- Join Date
- Jul 2010
- Posts
- 13
What you could do is rename the index.php to something like home.php
And replace index.php with redirect to to home.php or use htaaccess. Such as redirect /index.php www.yourdomain.com/home.php.
-
12-18-2011, 03:26 AM #23New Member
- Join Date
- Dec 2011
- Posts
- 2
301 Redirect htaccess = best solution
-
12-22-2011, 12:13 PM #24New Member
- Join Date
- Dec 2011
- Posts
- 4
Wow its a good thing to know thanks Boss
-
01-03-2012, 02:25 PM #25New Member
- Join Date
- Jan 2012
- Posts
- 2
crea8ivedesign.com
hi
yes its code its currupt they can verify by phpcake
regards
crea8ivedesign.com