#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    2
    Rep Power
    0

    Noob at .htaccess and mod rewrite


    I'm really new at this, only started my hand at hosting a website 3 or 4 days ago and I don't really have any previous experience so please excuse me for not simply following the tutorial.

    Ideally what I wanted to do is this:
    Code:
    Alias /sync /home/private/weave/index.php
    But I can't, my host doesn't allow write access to the httpd.conf file or any of the other apache files.

    I'm under the impression that mod rewrite and .htaccess can create something similar to alias, but I'm not really sure how it's done. The one's I've created so far haven't been very successful.

    If anyone could help me with this, it would be greatly appreciated.
    I'm not sure what is necessary, so I'll try provide as many details as possible.

    The full path to my server is:
    Code:
    /f5/somn/public/
    this corresponds to:
    Code:
    mydomain.com/
    The full path to the folder I want aliased is:
    Code:
    /f5/somn/public/sync/
    this corresponds to:
    Code:
     mydomain.com/sync
    The full path to the folder this alias should link to is:
    Code:
    /f5/somn/private/weave/
    This does not have an outward address

    this is what I have so far in my .htaccess (/f5/somn/public/.htaccess):
    Code:
    RewriteEngine On
    RewriteRule /sync/(.+)$ *and then I don't know what goes here*
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7171
    What does there is the file you want to run. Something like /home/private/weave/$1

    You probably want to anchor /sync/ to the beginning of the URL too, ^/sync
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    2
    Rep Power
    0
    Im not exactly sure how I'm meant to set this up, but I'm under the impression that /sync should point to /weave/index.php such that the php file recieves a path.
    When I try to navigate to the index file in my browser it prints
    "No path found"
    Here is the contents of that php file:
    Code:
    <?php  # ***** BEGIN LICENSE BLOCK ***** # Version: MPL 1.1/GPL 2.0/LGPL 2.1 # # The contents of this file are subject to the Mozilla Public License Version # 1.1 (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # http://www.mozilla.org/MPL/ # # Software distributed under the License is distributed on an "AS IS" basis, # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License # for the specific language governing rights and limitations under the # License. # # The Original Code is Weave Minimal Server # # The Initial Developer of the Original Code is # Mozilla Labs. # Portions created by the Initial Developer are Copyright (C) 2008 # the Initial Developer. All Rights Reserved. # # Contributor(s): #	Toby Elliott (telliott@mozilla.com) #   Luca Tettamanti # # Alternatively, the contents of this file may be used under the terms of # either the GNU General Public License Version 2 or later (the "GPL"), or # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), # in which case the provisions of the GPL or the LGPL are applicable instead # of those above. If you wish to allow use of your version of this file only # under the terms of either the GPL or the LGPL, and not to allow others to # use your version of this file under the terms of the MPL, indicate your # decision by deleting the provisions above and replace them with the notice # and other provisions required by the GPL or the LGPL. If you do not delete # the provisions above, a recipient may use your version of this file under # the terms of any one of the MPL, the GPL or the LGPL. # # ***** END LICENSE BLOCK *****  	require_once 'weave_storage.php'; 	require_once 'weave_basic_object.php'; 	require_once 'weave_utils.php';  	header("Content-type: application/json");  	$server_time = round(microtime(1), 2); 	header("X-Weave-Timestamp: " . $server_time);  	#Basic path extraction and validation. No point in going on if these are missing 	$path = '/'; 	if (!empty($_SERVER['PATH_INFO'])) 		$path = $_SERVER['PATH_INFO']; 	else if (!empty($_SERVER['ORIG_PATH_INFO'])) 		$path = $_SERVER['ORIG_PATH_INFO']; 	else 		report_problem("No path found", 404);  	$path = substr($path, 1); #chop the lead slash 	list($version, $username, $function, $collection, $id) = explode('/', $path.'///');  	if ($version != '1.0' && $version != '1.1') 		report_problem('Function not found', 404);  	if ($function != "info" && $function != "storage") 		report_problem(WEAVE_ERROR_FUNCTION_NOT_SUPPORTED, 400);  	if (!validate_username($username)) 		report_problem(WEAVE_ERROR_INVALID_USERNAME, 400);  	#only a delete has meaning without a collection 	if ($collection) 	{ 		if (!validate_collection($collection)) 			report_problem(WEAVE_ERROR_INVALID_COLLECTION, 400); 	} 	else if ($_SERVER['REQUEST_METHOD'] != 'DELETE') 		report_problem(WEAVE_ERROR_INVALID_PROTOCOL, 400);   	#quick check to make sure that any non-storage function calls are just using GET 	if ($function != 'storage' && $_SERVER['REQUEST_METHOD'] != 'GET') 		report_problem(WEAVE_ERROR_INVALID_PROTOCOL, 400);    	#user passes preliminaries, connections made, onto actually getting the data 	try 	{ 		$db = new WeaveStorage($username);  		#Auth the user 		verify_user($username, $db);  		#user passes preliminaries, connections made, onto actually getting the data 		if ($_SERVER['REQUEST_METHOD'] == 'GET') 		{ 			if ($function == 'info') 			{ 				switch ($collection) 				{ 					case 'quota': 						exit(json_encode(array($db->get_storage_total()))); 					case 'collections': 						exit(json_encode($db->get_collection_list_with_timestamps())); 					case 'collection_counts': 						exit(json_encode($db->get_collection_list_with_counts())); 					case 'collection_usage': 						$results = $db->get_collection_storage_totals(); 						foreach (array_keys($results) as $collection) 						{ 							$results[$collection] = ceil($results[$collection] / 1024); #converting to k from bytes 						} 						exit(json_encode($results)); 					default: 						report_problem(WEAVE_ERROR_INVALID_PROTOCOL, 400); 				} 			} 			elseif ($function == 'storage') 			{ 				if ($id) #retrieve a single record 				{ 					$wbo = $db->retrieve_objects($collection, $id, 1); #get the full contents of one record 					if (count($wbo) > 0) 					{ 						$item = array_shift($wbo); 						echo $item->json(); 					} 					else 						report_problem("record not found", 404); 				} 				else #retrieve a batch of records. Sadly, due to potential record sizes, have the storage object stream the output... 				{ 					$full = array_key_exists('full', $_GET) && $_GET['full'];  					$outputter = new WBOJsonOutput($full);  					$params = validate_search_params();  					$ids = $db->retrieve_objects($collection, null, $full, $outputter, 								$params['parentid'], $params['predecessorid'], 								$params['newer'], $params['older'], 								$params['sort'], 								$params['limit'], $params['offset'], 								$params['ids'], 								$params['index_above'], $params['index_below'], $params['depth'] 								); 				} 			} 		} 		else if ($_SERVER['REQUEST_METHOD'] == 'PUT') #add a single record to the server 		{ 			$wbo = new wbo(); 			if (!$wbo->extract_json(get_json())) 				report_problem(WEAVE_ERROR_JSON_PARSE, 400);  			check_quota($db); 			check_timestamp($collection, $db);  			#use the url if the json object doesn't have an id 			if (!$wbo->id() && $id) { $wbo->id($id); }  			$wbo->collection($collection); 			$wbo->modified($server_time); #current microtime  			if ($wbo->validate()) 			{ 				#if there's no payload (as opposed to blank), then update the metadata 				if ($wbo->payload_exists()) 					$db->store_object($wbo); 				else 					$db->update_object($wbo); 			} 			else 			{ 				report_problem(WEAVE_ERROR_INVALID_WBO, 400); 			} 			echo json_encode($server_time); 		} 		else if ($_SERVER['REQUEST_METHOD'] == 'POST') 		{ 			$json = get_json();  			check_quota($db); 			check_timestamp($collection, $db);  			$success_ids = array(); 			$failed_ids = array();  			$db->begin_transaction();  			foreach ($json as $wbo_data) 			{ 				$wbo = new wbo();  				if (!$wbo->extract_json($wbo_data)) 				{ 					$failed_ids[$wbo->id()] = $wbo->get_error(); 					continue; 				}  				$wbo->collection($collection); 				$wbo->modified($server_time);   				if ($wbo->validate()) 				{ 					#if there's no payload (as opposed to blank), then update the metadata 					if ($wbo->payload_exists()) 					{ 						$db->store_object($wbo); 					} 					else 					{ 						$db->update_object($wbo); 					} 					$success_ids[] = $wbo->id(); 				} 				else 				{ 					$failed_ids[$wbo->id()] = $wbo->get_error(); 				} 			} 			$db->commit_transaction();  			echo json_encode(array('success' => $success_ids, 'failed' => $failed_ids)); 		} 		else if ($_SERVER['REQUEST_METHOD'] == 'DELETE') 		{ 			check_timestamp($collection, $db);  			if ($id) 			{ 				$db->delete_object($collection, $id); 			} 			else if ($collection) 			{ 				$params = validate_search_params();  				$db->delete_objects($collection, null, 								$params['parentid'], $params['predecessorid'], 								$params['newer'], $params['older'], 								$params['sort'], 								$params['limit'], $params['offset'], 								$params['ids'], 								$params['index_above'], $params['index_below'] 							); 			} 			else 			{ 				if (!array_key_exists('HTTP_X_CONFIRM_DELETE', $_SERVER)) 					report_problem(WEAVE_ERROR_NO_OVERWRITE, 412);  				$db->delete_user($username); 			}  			echo json_encode($server_time);  		} 		else 		{ 			#bad protocol. There are protocols left? HEAD, I guess. 			report_problem(1, 400); 		} 	} 	catch(Exception $e) 	{ 		report_problem($e->getMessage(), $e->getCode()); 	}   #The datasets we might be dealing with here are too large for sticking it all into an array, so #we need to define a direct-output method for the storage class to use. If we start producing multiples #(unlikely), we can put them in their own class.  class WBOJsonOutput { 	private $_full = null; 	private $_comma_flag = 0; 	private $_output_format = 'json';  	function __construct ($full = false) 	{ 		$this->_full = $full; 		if (array_key_exists('HTTP_ACCEPT', $_SERVER) 			&& !preg_match('/\*\/\*/', $_SERVER['HTTP_ACCEPT']) 			&& !preg_match('/application\/json/', $_SERVER['HTTP_ACCEPT'])) 		{ 			if (preg_match('/application\/whoisi/', $_SERVER['HTTP_ACCEPT'])) 			{ 				header("Content-type: application/whoisi"); 				$this->_output_format = 'whoisi'; 			} 			elseif (preg_match('/application\/newlines/', $_SERVER['HTTP_ACCEPT'])) 			{ 				header("Content-type: application/newlines"); 				$this->_output_format = 'newlines'; 			}  		} 	}  	function set_format($format) 	{ 		$this->_output_format = $format; 	}   	function output($sth) 	{ 		if (($rowcount = $sth->rowCount()) > 0) 		{ 			header('X-Weave-Records: ' . $rowcount); 		} 		if ($this->_output_format == 'newlines') 		{ 			return $this->output_newlines($sth); 		} 		elseif ($this->_output_format == 'whoisi') 		{ 			return $this->output_whoisi($sth); 		} 		else 		{ 			return $this->output_json($sth); 		} 	}  	function output_json($sth) 	{ 		echo '[';  		while ($result = $sth->fetch(PDO::FETCH_ASSOC)) 		{ 			if ($this->_comma_flag) { echo ','; } else { $this->_comma_flag = 1; } 			if ($this->_full) 			{ 				$wbo = new wbo(); 				$wbo->populate($result); 				echo $wbo->json(); 			} 			else 				echo json_encode($result{'id'}); 		}  		echo ']'; 		return 1; 	}  	function output_whoisi($sth) 	{ 		while ($result = $sth->fetch(PDO::FETCH_ASSOC)) 		{ 			if ($this->_full) 			{ 				$wbo = new wbo(); 				$wbo->populate($result); 				$output = $wbo->json(); 			} 			else 				$output = json_encode($result{'id'}); 			echo pack('N', mb_strlen($output, '8bit')) . $output; 		} 		return 1; 	}  	function output_newlines($sth) 	{ 		while ($result = $sth->fetch(PDO::FETCH_ASSOC)) 		{ 			if ($this->_full) 			{ 				$wbo = new wbo(); 				$wbo->populate($result); 				echo preg_replace('/\n/', '\u000a', $wbo->json()); 			} 			else 				echo json_encode($result{'id'}); 			echo "\n"; 		} 		return 1; 	} } ?>

IMN logo majestic logo threadwatch logo seochat tools logo