Need Help With The Header() Function - I am redirecting from my old site

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > PHP Programming

Need Help With The Header() Function - I am redirecting from my old site

Amezis
Over a month ago, I bought a domain name for my site, but my site is still not indexed.

I did everything needed to get indexed, but I forgot one thing: The old site had exactly the same content as the new one. So I had duplicate content. Therefore, I want my old site to redirect the user to the new site with this script:

CODE
<?php
header("Location: http://www.global-rs.com" . $_SERVER['REQUEST_URI']);
exit;
?>

global-rs.com is my new URL. However, on my old site, which I will be placing this code on, there is a problem: It was a free host, not trap17 (I already had another site hosted here when creating the other site). They didn't offer subdomain, it was just a directory: thehost.com/globalrs.

The code shown above will redirect me to global-rs.com/globalrs/someurl

But is there a way to remove globalrs/ from the redirection, so it will only redirect the user to global-rs.com/someurl?

 

 

 


Reply

electriic ink
Try this code:

CODE
<?

$thisuri = $_SERVER["REQUEST_URI"];

$noSubDir = str_replace("/global_rs", "/", $thisuri);

header("location: http://globalrs.com" . $noSubDir);

?>


$noSubDir uses php's str_replace function to replace all instances of /global_rs with /.

Should work properly.....

Reply

Amezis
Thanks, but there were some errors with your code.
CODE
<?

$thisuri = $_SERVER["REQUEST_URI"];

$noSubDir = str_replace("/globalrs/", "/", $thisuri);

header("location: http://global-rs.com" . $noSubDir);

?>

This is how it should be. But anyway, thanks alot for the help! biggrin.gif

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Similar Topics

Keywords : header, function, redirecting, site

  1. PHP Function To Add Previous and Next Page Feature
    useful php function (5)
  2. Endif function?
    (6)
    As you get noticed before, I am studying PHP in examples like using the tutorials as well as books
    itself. Through my readings, I get this function CODE <?php endif; ?> a lot of times.
    So, what do you mean by this function, and what does it do exactly?....
  3. Xbox Gamertag Profile On Site
    (2)
    Alright, first off, sorry about the title, can't exactly explain it well. Basically, I want to
    have it so; 1. My users sign up on my website (easy enough, don't need help with) Now, this
    part might get confusing, but I need major help, as I see no way of doing it, yet I would love for
    it to happen. When they post on my website (comment), (this part I don't need help with), I
    wish for their gamer profile to show up under their name, so It'll say; Nate posted on (date):
    (gamer profile here) blah blah blah the trouble is, I have no idea how to get the ....
  4. Arrays Outside A Function
    Need to have arrays available to all functions. (3)
    I've got a bunch of arrays that i want to use for more then 1 function. when i declear the
    arrays outside a function i cant use it in a function. This code was originally written in
    javascript by another person but since I plan to use it and extend it with php I had to change it
    from javascript to php code. In the javascript code the arrays were decleared outside the functions
    with 'var arrayname' I read somewhere that declearing javascript variables with
    'var' gives it global access. Any ideas on how I can go about declearing 1 set of these
    arrays t....
  5. Html Site With Login
    Is it possible? (2)
    Hello. I´m building my own site and I need some help... Is it possible to use a login sistem in php
    and mysql database in a html site? ....
  6. Connecting Php Site To Database
    (6)
    Please Help Me with this site's error http://gatewaybiz.x10hosting.com/surf/ ....
  7. How To Check If Fsockopen Function Is Enabled?
    (2)
    Hi, I have VPS (virtual private server) and I have access to php.ini file. Is there any script that
    will show that fsockopen function is enabled or where do I have to enable it? Searched google and
    here and couldn't find anything. Thanks! ....
  8. Displaying Your Phone Number On A Wap Site
    (3)
    I have a wap site elitezone.co.za and what i want to add is a code to the index page that displays
    your operator and phone number. Does any one know the coding for this function if so please show me
    here. Help will appriacated. Topic title modified. ....
  9. Php Explode Function Help
    (4)
    I am having trouble creating a script, all i want to achieve is to: 1. Select the variable from my
    mysql database, which is in a format of : id|id|id|id| and so on... 2. Split them into separate
    variables by using : $songexploded = explode("|",$ttyo ); 3. Then this is the bit I'm
    stuck on trying to create a while loop from the $songexploded variables. So(this might not be
    correct but you should get the idea).. CODE $x=1; while ($songexploded
    ==$result) echo $songexploded[$x].'<br>'; }....
  10. The Best Zip Function
    (1)
    hi my 6th code is very useful, you can zip your file by this: CODE <? class dZip{     var
    $filename;     var $overwrite;          var $zipSignature =
    "\x50\x4b\x03\x04"; // local file header signature     var
    $dirSignature = "\x50\x4b\x01\x02"; // central dir header signature
        var $dirSignatureE= "\x50\x4b\x05\x06"; // end of central dir
    signature     var $files_count  = 0;     var $fh;          Function
    dZip($filename, $overwri....
  11. Mail() Clone
    A PHP mail() function clone (5)
    A lot of free web hosts have disabled the mail() function so you cannot send emails using PHP. Does
    anybody know of a script that makes a function "like" mail but is able to be installed in a web
    accessible directory and called included into another script and called like that? Or maybe you know
    how to make such a function? I just really need to find a way around the free hosts turning of the
    mail() function. I need to figure out a way to send emails.....
  12. New Arisen Site Problem
    Nettek Login Trouble (2)
    Okay, so I installed Nettek and got everything set up. But every time I try and login, it says
    it's incorrect. I've gone into the Database and gotten the password and since it was
    simple, put them in and had tried but with no success. I tried changing the password but I still
    couldn't get in. I tried adding another login and it still didn't work. I have no idea
    what's wrong and I need some help.....
  13. Php Problems
    Clan Web site Problem (3)
    Okay, so I have an old version of Nettek that I would like to modify. There is a bug that when you
    get to the rank required for Set Rank, you can set your rank or other people's ranks to what
    ever you want, even Webmaster and that's something I'd like to not have. I am wondering how
    to fix the problem. What would I modify in the coding to set have it so you can only move people up
    to 1 rank below you at best? I'm still learning PHP and can't modify things like this quite
    yet.....
  14. [php](simple) Using Functions To Combine Values In A Form
    Really simple example on how to combine values with function (2)
    I just learned this simple method on how to use functions to combine two values from a form. First
    we create ourselves a simple POST form CODE <form method="POST"> Name:
    <input type="text" name="nickname"> Location: <input
    type="text" name="location"> <input type="submit"
    value="Input"> </form> Now we add this php to that same file CODE
    <?php $nick = $_POST['nickname']; $location =
    $_POST['location' ....
  15. [php] Header Function
    (2)
    Header function Greetings we are going to use the header() funtion to redirect start making a
    file called page.php at the top of the file add CODE <?php ?> Example 1 After
    CODE header('Location: http://www.trap17.com'); the LOCATION means
    where you want it to go. Example 2 you also can define a file that you want to redirect to After
    CODE header('Location: index.php'); Example 3 you also can add a timer to
    it /laugh.gif" style="vertical-align:middle" emoid=":lol:" border="0" alt=....
  16. Use Bb Code On Your Site!
    Just like on forums! (7)
    To use this you must have PHP support on your server. Just use this code: CODE <?php
    $content = "Hello, World!"; $html = array('[b]',
    '[/b]', '[i]', '[/i]', '[u]',
    '[/u]'); $replacements = array ('<b>',
    '</b>', '<i>', '</i>', '<u>',
    '</u>'); $content = str_replace($html, $replacements,
    $content); ?&....
  17. Error With Joomla Template
    cant find function (1)
    Hello! I am working on my template in Dreamweaver and i am using joomla extensions for
    dreamweaver! When i start my page with joomla stand alone server(jsas) i get this errors on the
    bottom of the page! QUOTE Warning:
    mosloadcomponent(w:/www/Joomla/components/com_banner/banner.php) : failed to open stream: No such
    file or directory in w:\www\Joomla\includes\frontend.php on line 66 Warning:
    mosloadcomponent(w:/www/Joomla/components/com_banner/banner.php) : failed to open stream: No such
    file or directory in w:\www\Joomla�....
  18. Cms Opensource
    great cms reviews site (1)
    Hello... you can find great cms on http://www.opensourcecms.com <<< there you can find cms like
    mambo,joomla,wordpress,etc <<....
  19. The Extract() Function
    Something I just found out (6)
    The extract() function is used in PHP to take an array and split it up into variables. MySQL
    queries can be parsed this way. Below is an example. CODE $query =
    mysql_query("select username, password from users where uid=1"); $result =
    mysql_fetch_array($query, mysql_assoc); extract($result); print "Your
    username is : $username"; The extract() function works for ANY array, including
    $_POST, and $_GET. Makes processing form data a LOT easier /biggrin.gif"
    style="vertical-align:midd....
  20. How Good Is This Data Cleaning Function?
    (2)
    Hi all, this is my first function and as part of a script and i just want to know a couple of
    things. here is the code for the function: CODE <? function
    clean($dirty_string) { $muddy_string = stripslashes($dirty_string);
    $murky_string = strip_tags($muddy_string); $clean_string =
    htmlentities($murky_string);      }; ?> So the first thing is how secure is
    it? the script this will be used in connects to a database and sends an email so it needs to stop
    SQL injections and any email ab....
  21. Beginner's Php Tutorial Online At My Site
    (12)
    Hey everyone, over the last week I've been writing a PHP tutorial aimed at absolute beginners
    who have never even seen the syntax of PHP before let alone wrote a PHP script! The tutorial
    assumes you have a basic knowledge of HTML (for the tutorial you will need to write a couple of
    hyper links and forms, nothing complex!) and an internet browser. It tells you about where to
    find the other software needed (apache/XAMPP and a script.text editor) and how to check if it is
    working. The tutorial is basic and focuses on the use of the ECHO, INCLUDE/REQUIRE and I....
  22. Header Redirect Errors
    (5)
    Hi, I am using the header function to redirect after the processing of the form. I have to specify
    a internal link using '#link'. This works in Firefox and opera. But in Internet Explorer
    internal linking when done from a redirect is not working for somewhat reasons. e.g.
    header("Location: http://www.example.com/index.php#link"); this works in Firefox and Opera but
    not in Internet Explorer . IE just accepts 'http://www.example.com/index.php' instead of
    http://www.example.com/index.php#link Please help me if you know anything about this. Well ther....
  23. Explode Function Help
    need help from you programmers! (1)
    /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> Hi I am robert I
    need some help with some php coding. I am stuck with a explode function. Here is the code:
    $username = $check ; $query="SELECT `buildings` FROM `authuser` WHERE
    `uname` = '$username'"; $result=mysql_query($query);
    $result=mysql_result($result,0);
    list($building1,$building2,$building3,$building4,$building5,$building6
    ,$building7,$building8,$building9,....
  24. Email Header Inject Test
    (0)
    So I'm trying to write a script to check if someone is trying to do a header inject using my web
    based email form. The problem is that, regardless of the content, it is being tagged as hijacked.
    The following is the relevant part of my code: CODE $ip=$_POST['ip'];
            $httpref=$_POST['httpref'];
            $httpagent=$_POST['httpagent'];
            $visitor=$_POST['visitor'];
            $visitormail=$_POST['visitormail'];         $s....
  25. Regexp Function Preg_match_all()
    preg_match_all() - Help me (0)
    Hi, I got a new problem which has caused me to go mad but no solution. preg_match_all() - is the
    problem. I have something like this: CODE [ol] [li]Test1[/li]
    [li]Test2[/li] [li]Test3[/li] [li]Test4[/li]
    [li]Test5[/li] [/ol] Some text.Some text.Some text. [ol]
    [li]Test1[/li] [ol] [li]Test1[/li]
    [li]Test2[/li] [li]Test3[/li] [li]Test4[/li]
    [li]Test5[/li] &....
  26. Wap Redirection
    Usefull code that all wap site owners should use! (12)
    Use this code to redirect pc users from your wap site to web site: include above page header this
    code: CODE <?php $mywebsite = "forum/index.php"; $browser = explode
    ('/', $HTTP_USER_AGENT); if($browser[0]=="IE"){
    header ('Location: $mywebsite');} ?> ....
  27. Php Header Problem
    i always got header problem (11)
    i really hate the header function it always get an error saying ( cannot ------- headers already
    sent by----- ) and here's my error: Warning: session_start(): Cannot send session cookie -
    headers already sent by (output started at /home/adly3000/public_html/Mail/index.php:5) in
    /home/adly3000/public_html/Mail/index.php on line 81 Warning: session_start(): Cannot send session
    cache limiter - headers already sent (output started at /home/adly3000/public_html/Mail/index.php:5)
    in /home/adly3000/public_html/Mail/index.php on line 81 Warning: Cannot modify header ....
  28. Include File.php?id=something
    using the include() function (13)
    Well, I am making a full CMS system for my site, and want to make the index.php file to include the
    view.php?id=1 file. I tried with this code, but it didn't work: CODE <?php include
    'view.php?id=1' ?> This is the error I get: CODE Warning:
    main(view.php?id=1) [function.main]: failed to open stream: Invalid argument
    in C:\server\xampp\htdocs\test\index.php on line 1 Warning:
    main() [function.include]: Failed opening 'view.php?id=1' for inclusion
    (i....
  29. How To Use A Link To Call Function In Php?
    (8)
    The title says it all, really. How do you call a function using in PHP? I'm doing a project
    and I stumbled upon this problem. I don't want to use query string in the href part like
    since that would mess up the other part of my code. Can anyone pleae help me? I've pasted the
    code below. /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /> Thanksh.
    CODE <?php   function display($x){ //coding goes here.   } ?>
    <html> <body> <p align="center"> <a href="what g....
  30. Getting List Of Directories And Files Using Php
    PHP Function for Directory and File List (6)
    is there a php function that lists the content of some folder.... example: /New folder new.txt
    left.gif download.zip dc.exe ....so is there..? /rolleyes.gif' border='0'
    style='vertical-align:middle' alt='rolleyes.gif' /> ....

    1. Looking for header, function, redirecting, site

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for header, function, redirecting, site

*MORE FROM TRAP17.COM*
advertisement



Need Help With The Header() Function - I am redirecting from my old site



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE