PHP - Redirect Main Domain To Subdomain
Hi,
I have an address on my main server http://www.website.com/directory and would like to redirect it to a subdomain http://subdomain.website.com/directory
The subdomain is not pointing to the same server as the main domain.
How would I set up a redirect in htaccess?
Thanks!
Similar Tutorialshey all, I've been struggling with this for the last few days and can't figure it out... I'm trying to build a fairly complex uploading system. the thing i'm getting stuck with is trying to copy/move the uploaded files from the domain name to a subdomain Ex: $path1 = "/var/www/vhosts/domain.com/httpdocs/new/test/test.jpg"; $path2 = "/var/www/vhosts/domain.com/subdomains/img/httpdocs/test/test.jpg"; Dedicated server running RHEL with Plesk The problem seems to be an open_basedir restriction. My question is... are there any work-arounds open_basedir and if not what are the implications of disabling it??? Any help is greatly appreciated. Thank you for your time c Hi all, Im trying to move files that im uploading from my main domain to a sub domain. I think I can achieve this using passthru? Im having issues with this, can any one point me in the right direction please? Thanks, Phil My service allows users to generate subdomains based off their username(testguy.mydomain.com). I've created a wildcard subdomain for this, so the dynamic subdomains work wonderfully.
I've added a parked domain where my domain is supposed to mirror the given subdomain. However, when I go to the domain.com, it redirects to the subdomain, changing the URL in the address bar. Any ideas?
Or if there a better way to mirror a subdomain while showing the original domain in the address bar?
Edited by fitguydan, 12 June 2014 - 11:57 PM. Problem: The page does not redirect the end user to main.php. Notice: Use of undefined constant name_id - assumed 'name_id' in C:\x\xampp\htdocs\pages\form_process.php on line 48 Warning: Cannot modify header information - headers already sent by (output started at C:\x\xampp\htdocs\pages\form_process.php:48) in C:\x\xampp\htdocs\pages\form_process.php on line 87 The error messages displayed above make it seem like they are connected to the problem, but I don't understand why 'name_id' is undefined as its auto increments in mysql. I also think my .htaccess might be preventing me from redirecting, is that possible? " header('Refresh: 5; URL=http://localhost/pages/main.php'); " Goal: redirect user to main.php without error messages being displayed. form_process.php <?php //let's start our session, so we have access to stored data session_start(); if (isset($_POST['terms_and_conditions']) == 0) { // the code was incorrect // handle the error accordingly with your other error checking // or you can do something really basic like this die('You must agree to the terms and conditions to create a profile. Go back and try again.'); } include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php'; $securimage = new Securimage(); if ($securimage->check($_POST['captcha_code']) == false) { // the code was incorrect // handle the error accordingly with your other error checking // or you can do something really basic like this die('The code you entered was incorrect. Go back and try again.'); } else { include 'db.inc.php'; $db = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD) or die ('Unable to connect. Check your connection parameters.'); mysql_select_db(MYSQL_DB, $db) or die(mysql_error($db)); $error = array(); $query = 'SELECT name FROM user WHERE ' . 'name = "' . mysql_real_escape_string($_SESSION['values']['name'], $db) . '"' ; $result = mysql_query($query, $db) or die(mysql_error($db)); if(mysql_num_rows($result) > 0) { $error['uname'] = '<p class="errText">Username is taken.</p>'; header('Refresh: 5; URL=form1.php'); } //let's create the query else{ $query = sprintf("INSERT INTO user ( name_id, name, password) VALUES ('%s','%s','%s')", name_id, mysql_real_escape_string($_SESSION['values']['name']), mysql_real_escape_string(md5(SALTY . $_SESSION['values']['password']))); //let's run the query $result = mysql_query($query, $db) or die(mysql_error($db)); $name_id = mysql_insert_id(); $query = sprintf("INSERT INTO contact ( name_id, first_name, last_name, email, address, city, county, post, home, mobile) VALUES (LAST_INSERT_ID(),'%s','%s','%s','%s','%s','%s','%s','%s','%s')", mysql_real_escape_string($_SESSION['values']['first_name']), mysql_real_escape_string($_SESSION['values']['last_name']), mysql_real_escape_string($_SESSION['values']['email']), mysql_real_escape_string($_SESSION['values']['address']), mysql_real_escape_string($_SESSION['values']['city']), mysql_real_escape_string($_SESSION['values']['county']), mysql_real_escape_string($_SESSION['values']['post']), mysql_real_escape_string($_SESSION['values']['home']), mysql_real_escape_string($_SESSION['values']['mobile'])); //let's run the query $result = mysql_query($query, $db) or die(mysql_error($db)); $name_id = mysql_insert_id(); $query = sprintf("INSERT INTO profile ( name_id, bi, ex) VALUES (LAST_INSERT_ID(),'%s','%s')", mysql_real_escape_string($_SESSION['pro']['bi']), mysql_real_escape_string($_SESSION['pro']['ex'])); $result = mysql_query($query, $db) or die(mysql_error($db)); $_SESSION['logged'] = 1; header('Refresh: 5; URL=http://localhost/pages/main.php'); } ?> <html> <head> <title>Register</title> </head> <body> <p><strong>Thank you <?php echo $_SESSION['values']['name']; ?> for registering!</strong></p> <p>Your registration is complete! You are being sent to the page you requested. If your browser doesn't redirect properly after 5 seconds, <a href="main.php">click here</a>.</p> </body> </html> <?php session_destroy(); die(); } ?> Hello all, I have this issue: I have a form with several fields. I need to save to a session variable (in submit page) all of the fields upon submit and then post some of the fields to a https site using a POST request (i.e., doing a header('Location: https://mynewdomain.com/page.cfm?'.$data) won't cut it). Now, I can do it with javascript... a whole bunch of hidden fields in the between page and then auto submit the form to the mynewdomain.com domain using the post method. I am wondering whether there would be a better way for that. I know that Curl does it, with one glitch. When I set the parameter CURLOPT_FOLLOWLOCATION to true it redirects the user BUT it doesn't load any css or javascript from the new page. People say on the web to do a request for each file but I haven't figured out how to do it. Can anyone post an elegant/concrete solution to this problem or should I resort to Javascript? Thanks menwn Ok, I have a download script. The script is called like: http://www.site.net/index.php?action=downloadfile&filename=file001.zip&directory=directory12& The download file code is below. My site hosts quite a few files that get linked on other websites. Problem is, when that link is clicked, obviously it just starts the file download, as if it were a direct link to the file. What I need to do, is still have it download the file when the link is clicked, but I would also like it to redirect the browser to my homepage as well. I tried placing this after the download headers but it didn't work. header("Location: http://www.site.net"); Can anyone give me an idea how I can get the code to do that? Keep in mind that I'm not fluent in PHP. case 'downloadfile'; $filename = getGetVar('filename'); $directory = getGetDir('directory'); $current_dir = $uploads_folder_name; if ($directory != '') { $current_dir.="/$directory"; } $filename = basename($filename); if (!$grants[$user_status][DOWNLOAD]) { place_header($mess[111]); show_Contents(); break; } if (!file_exists("$current_dir/$filename")) { place_header($mess[125]); show_Contents(); break; } if (!is_path_safe($directory, $filename)) { place_header($mess[111]); show_Contents(); break; } list($upl_user, $upl_ip, $filestatus, $contents) = get_file_description("$current_dir/$filename", $comment_max_caracters); if ($validation_enabled && $filestatus == UNVALIDATED && !$grants[$user_status][VALIDATE]) { place_header($mess[111]); show_Contents(); break; } $size = filesize("$current_dir/$filename"); $daily_size = get_daydownload(); if (($max_daily_download_mb > 0) && (($size + $daily_size) > ($max_daily_download_mb * 1024 * 1024))) { place_header($mess[212]); show_Contents(); break; } $monthly_size = get_monthdownload(); if (($max_monthly_download_mb > 0) && (($size+$monthly_size) > ($max_monthly_download_mb * 1024 * 1024))) { place_header($mess[213]); show_Contents(); break; } increasefiledownloadcount("$current_dir/$filename"); increasebytecountdl("$destination/$userfile_name"); if (($user_status != ANONYMOUS) && ($logged_user_name != '')) // Update user statistics { list($files_uploaded, $files_downloaded, $files_emailed) = load_userstat($logged_user_name); $files_downloaded++; save_userstat($logged_user_name, $files_uploaded, $files_downloaded, $files_emailed, time()); } header("Content-Type: application/force-download; name=\"$filename\""); header("Content-Transfer-Encoding: binary"); header("Content-Length: $size"); header("Content-Disposition: attachment; filename=\"$filename\""); header("Expires: 0"); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); // Decrypt file if encryption enabled if ($encrypt_filecontent) { decrypt_file("$current_dir/$filename", true); } else { readfile_chunked("$current_dir/$filename"); } exit; break; I'm making an admin so I need to be able to do this: https://admin.mysite.com Run an upload image script from a file, saves image to folder in http://www.mysite.com Image Folder This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=359577.0 This topic has been moved to the corner of 3rd Avenue and mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=359430.0 I have two domains both running SSL. Let's call them old-domain and new-domain. old-domain is permanently redirecting traffic to new-domain. There are still a lot of links out there to old-domain with https://. If I were to remove SSL from old-domain but keep SSL on new-domain, I am betting that users will be getting some sort of certificate error. Right? Any way around that if I want to remove SSL from old-domain?
What is the easiest way to get the value of subdomain. For example, when browsing word1.example.com; how to get it (like $_GET['q']) to put "word1" into an string. I started http://forums.phpfre...h-common-names/ a while back, and basically heard that I should use separate domains if I wish to ensure that cookies cannot be manipulated between one another. For instance, each of the following three URLs will have their own cookies which cannot be accessed from the others.
joe.user-sites.example.com/index.php
joe.site-admin.example.com/index.php
main-site.example.com/index.php
Problem is I don't wish to force the user to use these long URLs. Instead, I wish the user to see:
joe.example.com/index.php
admin.joe.example.com/index.php (or joe.example.com/admin/index.php if it is easier to make secure)
example.com/index.php
How is this accomplished? Thank you
Hello. I am currently working on a new site (http://sa.cx) that is basically a free domain like this: (example.sa.cx). My main goal is to allow users to set the the full MX, CNAME, A and SOA records. Any ideas on how I could go about this using php? My initial thought would be via cURL. my site is laid out as follows: beta.domain.com/index.html <-- this page contains an ajax form scripts.domain.com/js/formoperations.js <--ajax javascript scripts.domain.com/php/msgsend.php <--ajax php script The PHP script which is posted below is to echo back "Thank you" once the form is processed & emailed. If the files are in the directories stated above the PHP script does not echo back. It still completes emailing the form data successfully but does the echo does not make it back to beta.domain/index.html. HOWEVER...if I move my PHP file to beta.domain.com/msgsend.php it works flawlessly. Why can't my script echo across subdomains? Thanks! Code: [Select] <?php $fname= urldecode($_GET['param']); $lname = urldecode($_GET['param1']); $email = urldecode($_GET['param2']); $details = urldecode($_GET['param3']); $datereported = date(n."/".j."/".Y." @ ".g.":".i." ".A); $text="<p><b>First Name:</b> ".$fname."</p><p><b>Last Name:</b> ".$lname."</p><p><b>Email Address:</b> ".$email."</p><p><b>Message:</b> ".$details."</p>-End Submission"; $plaintext="First Name: ".$fname."\nLast Name: ".$lname."\nEmail Address: ".$email."\nMessage: ".$details."\n\n End Submission"; $to = 'chris@domain.com'; $subject = 'Web Message'; $random_hash = md5(date('r', time())); $headers = "From: Web Message\r\nReply-To: info@domain.com"; $headers .= "\r\nContent-Type: text/html; charset='iso-8859-1' Content-Transfer-Encoding: 7bit"; ob_start(); ?> <img src="http://uniformimgs.domain.com/emailheadcontact.gif" alt="" /> <p style="font-family:Arial, Helvetica, sans-serif; font-size:12px; margin:15px 0 50px 0;"><?php echo $fname.' '.$lname; ?> has submitted a message from the website on <?php echo $datereported; ?>.</p> <?php echo $text; ?> <? $message = ob_get_clean(); if(mail($to, $subject, $message, $headers)) { echo '<h4>Thanks for your message '.$fname.'!</h4><br/><br/><br/><br/>'; $to = $email; $subject = 'Thanks for your message!'; $random_hash = md5(date('r', time())); $headers = "From: info@domain.com\r\nReply-To: info@domain.com"; $headers .= "\r\nContent-Type: text/html; charset='iso-8859-1' Content-Transfer-Encoding: 7bit"; ob_start(); ?> <img src="http://uniformimgs.domain.com/emailheadcontact.gif" alt="" /> <p style="font-family:Arial, Helvetica, sans-serif; font-size:12px; margin:15px 0 5px 0;">Dear <?PHP echo $fname ?>,</p> <p style="font-family:Arial, Helvetica, sans-serif; font-size:12px; margin:0;">Thank you for sending us a message from our website; we love hearing from you folks! If needed, we'll contact you as soon as possible in regards to your message.</p> <p style="font-family:Arial, Helvetica, sans-serif; font-size:12px; margin:20px 0 0 200px;">Sincerely,</p> <p style="margin: 10px 0 0 200px;"><img src="http://uniformimgs.domain.com/briansig.gif" alt="" /></p> <p style="font-family:Arial, Helvetica, sans-serif; font-size:10px; margin:0px 0 0 200px;">John R Smith, pricipal</p> <p style="font-family:Arial, Helvetica, sans-serif; font-size:10px; margin:200px 0 0 0">This email has been sent by an automated service</p> <? $message = ob_get_clean(); //send the email mail($to, $subject, $message, $headers); } else { echo "<h5>Oops! Seems like we have a problem.</h5><h6>Please try again later or call XXX-XX-XXX.</h6>"; } ?> I did a project for a client over a year ago and never ran into this problem on their shared server, but now I'm having this problem on my own... and I'm not sure why.
I want to give free members their own subdomain. I want the php files to scan the subdomain to determine which pages to display. So like my index.php would scan the subdomain and show the corresponding user's home page so that if you go to someguy.thisdomain.com, it would really just scan index.php at thisdomain.com and act accordingly.
On the other project, no extra folders were created. I know that subdomains can be created in cpanel and then extra folders would be added and whatnot, but I was able to effectively use subdomains for users without htaccess or any sort of cpanel functions.
The main problem is when I test subdomains. I have php code that just echos "Subdomain is blah" and it works when I go to www.mydomain.com and also just mydomain.com, but when I go to test.mydomain.com, it gives an error as if the domain doesn't exist.
This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=313168.0 Suppose, i have created a sub.domain.com and i want to include a file 'config.php' from root directory i.e domain.com . While i tried include("../config.php"); i wasn't successful. Anyone can help me please?? I need the solution very urgently, so please help me soon. pracasify@yahoo.com facebook.com/agptj I was wondering of it was possible to have a file say style.css in the root folder of a site like www.example.com/style.css and then get a subdomain called www.sub.example.com which points to www.example.com/subarea to get that file without the use of absolute paths? Sorry if its not clear. I'm trying to put together a script that redirects visitors based on their IP, user agent and/or referral url. Basically I want the script to scan these three factors from the visitor, if any of them turn out to match my redirect-requirement it redirects the user. I know the code is horribly coded, I'm incredibly new to the php-scene and consider myself a complete noob. As you can see I want redirected visitors to go to google.com and un-redirected to msn.com(examples). Really thankful for all the help I can get! Right now nothing works, any suggestions? <?php function redirect($page) { Header( "HTTP/1.1 301 Moved Permanently" ); header('Location: ' . $page); exit; } $referrals=array('pitchingit.org','referral2'); $badAgents = array("useragent1", "useragent2"); $deny = array("78.105.191..*","100.101.103..*"); if (in_array($_SERVER['HTTP_REFERER'], $referrals, FALSE)) { header("Location: http://www.google.com"); } else { header("Location: http://www.msn.com"); } if(in_array($_SERVER['HTTP_USER_AGENT'],$badAgents)) { redirect("http://www.google.com/"); exit(); } $add=$_SERVER['REMOTE_ADDR']; foreach ($deny as $ip) { if (preg_match("^.$add.*^",$ip)) { redirect("http://www.google.com"); } } redirect("http://www.msn.com"); ?> |