Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Redirect loop, subdomain in root, htaccess php

    Hello!

    My question :

    I have a domain (example.com). I also have a sub-domain (sub.example.com) that points to the root, as does example.com. I have an htaccess file that passes everything to /index.php (off the root). index.php manipulates the display based on http_host and request_uri. I have also set htaccess conditions to allow certain files / directories to be shown. The problem I have is that there is a redirect loop when I view the sub-domain and do not follow it with an excepted file or directory. The php checks if the domain is in a text file, and if it is not redirects to google.com. I am not understanding what is wrong.

    This is my first post to codingforums, so I'll start with my knowledge. I do not have much htaccess experience. I do know a bit about php from self studies. I have tried to post as much information as necessary to aid in your assistance. Lastly, thank you in advance!!

    Tested:

    [works] http://example.com
    [works] http://example.com/uri-string
    [works] http://example.com/2011-9xy9.css

    [fails] http://sub.example.com
    [fails] http://sub.example.com/uri-string
    [works] http://sub.example.com/2011-9xy9.css

    my htaccess file
    Code:
    RewriteEngine on
    Options +FollowSymlinks
    RewriteBase /
    
    # initial static rewrites, without conditions
    RewriteRule ^oldindex /main.php [NC,L]
    
    # allow access to the files inside specific directories, but not a directory listing..
    RewriteCond %{REQUEST_URI} !2011images/(.*)\.
    
    # allow access to these particular files...
    RewriteCond %{REQUEST_URI} !robots.txt$
    RewriteCond %{REQUEST_URI} !favicon.ico$
    RewriteCond %{REQUEST_URI} !2011-9xy9.css$
    RewriteCond %{REQUEST_URI} !index.php$
    RewriteCond %{REQUEST_URI} !main.php$
    
    # rewrite rules
    RewriteRule ^(.*)$ /index.php [NC,L]
    the php class that validates requesting http_host
    Code:
    class Common
    {
    	public $adminPath = "/path/to/admin/folder/";
    	public $homeAddress = "http://example.com";
    	
    	// FILE MANIPULATION //
    	public function FileWrite($location, $contents, $append)
    	{
    		if(($append == true) && (file_exists($location)))
    			$fileHandle = fopen($location, 'a');
    		else
    			$fileHandle = fopen($location, 'w');
    		fwrite($fileHandle, $contents);
    		fclose($fileHandle);	
    	}
    	
    	public function FileRead($location)
    	{
    		$contents = "";
    		if(file_exists($location))
    		{
    			$fileHandle = fopen($location, 'r');
    			$contents = fread($fileHandle, filesize($location));
    			fclose($fileHandle);
    		}
    		return $contents;
    	}
    	
    	// REDIRECTION //
    	public function Redirect($location)
    	{
    		header("Location: ".$location);
    	}
    	
    	// GENERAL OUTPUT //
    	public function Text()
    	{
    		return "object";
    	}
    }
    
    class DomainAddress extends Common
    {
    	private $address;
    	private $title;
    	private $subtitle;
    	private $links;
    	
    	public function DomainAddress($lookup)
    	{
    		$this->address = "http://".$_SERVER['HTTP_HOST'];
    		if($lookup == true)
    		{
    			// RETRIEVE OR REDIRECT //
    			if(!file_exists($this->adminPath."domain-address.txt"))
    				$this->Redirect($this->homeAddress);
    			$found = false;
    			$domainAddressLookup = explode("\n", $this->FileRead($this->adminPath."domain-address.txt"));
    			for($x = 0; $x < count($domainAddressLookup); $x++)
    			{
    				$domainAddressLookup[$x] = explode("~", $domainAddressLookup[$x]);
    				if($domainAddressLookup[$x][0] == $this->address)
    				{
    					$this->title = $domainAddressLookup[$x][1];
    					$this->subtitle = $domainAddressLookup[$x][2];
    					$this->links = $domainAddressLookup[$x][3];
    					$found = true;
    				}
    				if($found)
    					break;
    			}
    			if(!$found)
    			{
    				header("location: http://www.google.com");
    			}
    		}
    		else
    		{
    			$this->title = "Unknown Title";
    			$this->subtitle = "Unknown Subtitle";
    			$this->links = "No Links Found";
    		}
    	}
    	
    	public function Text()
    	{
    		return "<h1>$this->title</h1>\n<h2>$this->subtitle</h2>\n<h2>$this->address</h2>\n";
    	}
    	
    	public function Links()
    	{
    		return $this->links."\n";
    	}
    }
    I do repeat, EVERYTHING works as expected on http://example.com. Only the excepted files and directories work on http://sub.example.com.
    Last edited by The Baker Show; 12-20-2010 at 01:13 AM. Reason: missing exception for 2011-9xy9.css

  • #2
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry No answer?, so I have a temporary work around

    I understand I am new - to this forum, to htaccess, and the like. I do wish somebody would help me. Could you please tell me how how to make this redirection work?

    I have a temporary work around that avoids redirection for now. It simply reports an error message stating that the domain was not found in the domain-address.txt file. I would like the redirection for use with wildcard subdomains, in the case that a user enters a subdomain that has no information. I would like that to redirect to the main site http://9xy9.com. And yes, I know that I do not currently have a wildcard pointing to the root. GoDaddy does not let me. This is for future reference, should I soon change my host. The plan expires in May


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •