Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 26th May 2010, 06:08 PM   #1
Warrior Member
 
Join Date: 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default
How do you create this 301 redirect using PHP?
Share on: 
fb share twitter share gplus share more share

I would like www enforced and file structure intact.

e.g. subdomain[dot]domain[dot]com/bears[dot]php redirects to www[dot]newdomain[dot]com/bears[dot]php
AND/OR
subdomain[dot]domain[dot]com redirects to www[dot]newdomain[dot]com

e.g. newdomain[dot]com/bats[dot]php redirects to www[dot]newdomain[dot]com/bats[dot]php
AND/OR
newdomain[dot]com redirects to www[dot]newdomain[dot]com

How would I create a PHP(not .htaccess) redirect that incorporates both the examples above?

Would I use an add-on domain? Or would a parked domain be better?

*replace [dot] with .
evilbone is offline  
Unread 26th May 2010, 06:12 PM   #2
HyperActive Warrior
War Room Member
 
RokNStoK's Avatar
 
Join Date: 2010
Location: Portland Oregon
Posts: 121
Thanks: 24
Thanked 7 Times in 6 Posts
Default
Re: How do you create this 301 redirect using PHP?
Share on: 
fb share twitter share gplus share more share

Hi evilbone,
What's the difference between a PHP and .htaccess 301 redirect? Why would you prefer the PHP version? I want to redirect all the 'non www' pages on my site to their 'www' counterparts. Which way do you think I should use?

What do you think is better, www or no www?

Thanks evilbone!

Ken
www.monopolinks.com
Free One-Way Link Exchange
RokNStoK is offline  
Unread 27th May 2010, 06:34 AM   #3
Computer Geek :O
 
Join Date: 2010
Location: England
Posts: 25
Thanks: 0
Thanked 2 Times in 2 Posts
Default
Re: How do you create this 301 redirect using PHP?
Share on: 
fb share twitter share gplus share more share

@evilbone,
Its pretty simple, its the same as a normal redirect accept you include and extra line before:

PHP Code:
<?php
header
("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.example.com/");
?>

<CrGeary.com/> is offline  
Unread 28th May 2010, 12:53 PM   #4
Warrior Member
 
Join Date: 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: How do you create this 301 redirect using PHP?
Share on: 
fb share twitter share gplus share more share

@RokNStok
What's the difference between a PHP and .htaccess 301 redirect?
The difference is the method.
Why would you prefer the PHP version?
It's easier for me.
Which way do you think I should use?
This is difficult to answer because you haven't explained your situation sufficiently.
What do you think is better, www or no www?
You should decide this on your own. Use a coin toss if you can't decide.

@<CrGeary.com/>
That code does take me to the new URL but doesn't load the same pages from the subdomain. See first example for what I mean.

Were my questions in my first post not specific enough?:confused:
evilbone is offline  
Unread 29th May 2010, 06:02 AM   #5
tks
Warrior Member
 
Join Date: 2010
Posts: 28
Thanks: 3
Thanked 1 Time in 1 Post
Default
Re: How do you create this 301 redirect using PHP?
Share on: 
fb share twitter share gplus share more share

How about this?
I use this to completely redirect to identical pages/directories

$new_location = 'your-new-domain'.$_SERVER['REQUEST_URI'];
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: $new_location" );
exit;

tks is offline  
Closed Thread


Bookmarks

Tags
301, php, redirect


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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 03:20 AM.