views:

57

answers:

3

I am running into the following issue:

Our members have a desire for personalized sites directly from our primary domain in the form of http://www.example.com/membername. I am looking at possibly solutions in two ways but neither are ideal (will be explained below).

Method 1 - ?Member=

In this method, I simply create a custom URL and store the information in the member's database profile. For example: if I want my "custom" URL to be jm4, for a consumer to visit my site, they must type in http://www.example.com?Member=jm4.

The site, of course, does a $_GET['Member'] to lookup the member information, stores the primary data in Session from the index page, then redirects to a homepage. The consumer no longer sees the membername in the URL but instead sees all the page names for www.example.com as if they simply visited the parent domain to start (each member's page has custom information however).

While this method works it presents the following problems:

  • The URL is not nearly as easy as /jm4 and any errors typing out the wildcard ?Members= will result in page error. Also, This method keeps that particular member's information in session (which is necessary browing from page to page on that particular member domain) and prevents somebody from simply typing http://www.example.com?Member=name2 to visit another site without clearing their session or closing the browser.

Method 2 - /membername

While the preferred method, currently the only way we know how to create is to manually generate an index file in a subfolder, redirect to the primary index then allow the consumer to view the member's personal site.

For example, if I visit www.example.com/jm4, I am hitting the /jm4 folder which contains index.php. Within this file simply contains:

<?php
session_start();
ob_start();

$_SESSION['AgentNumber'] = "779562";
header("Location: ../index.php");
exit;
?>

the primary index recognizes this with:

<?php
session_start();
ob_start();

if ($_SESSION['MemberNumber'] == NULL) {
     header("Location:ac/");
     exit;
}

$conn = mysql_connect("localhost", "USER", "PW");
mysql_select_db("DB",$conn);

$sql = "SELECT * FROM table WHERE MemberNumber = $_SESSION[MemberNumber]";
$result = mysql_query($sql, $conn) or die(mysql_error());
while ($newArray = mysql_fetch_array($result)) {
    $_SESSION['MemberName'] = $newArray['MemberName'];
    $_SESSION['MemberPhone'] = $newArray['MemberPhone'];
    $_SESSION['MemberMobile'] = $newArray['MemberMobile'];
    $_SESSION['MemberFax'] = $newArray['MemberFax'];
    $_SESSION['MemberEmail'] = $newArray['MemberEmail'];
    $_SESSION['MemberAddress'] = $newArray['MemberAddress'];
    $_SESSION['MemberCity'] = $newArray['MemberCity'];
    $_SESSION['MemberState'] = $newArray['MemberState'];
    $_SESSION['MemberZip'] = $newArray['MemberZip'];
    $_SESSION['MemberAltName'] = $newArray['MemberAltName'];
}
mysql_close($conn);
header("Location: home/");
exit;
?>

We would certainly prefer to use the second method in terms of 'ease' for the member but keep running into the following issues:

  1. We are forced to manually create a sub-folder and unique index.php file for each new member we onboard
  2. While the above probably could be automated (when new member creates profile, automatically generate php file and folder) but this is more complicated and we don't want to have 3000 subfolders on the primary domain.

Has anybody run into similar issues? If so, how did you go about solving it? What would you recommend based on my details above? Any advice is appreciated.

Also - using as subdomain (membername.example.com) is not preferred because our current SSL does not allow for wildcards.

EDIT 1 - EXISTING .HTACCESS FILE My existing .htaccess file on the site looks like this for reference:

ErrorDocument 404 /404.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
RewriteRule ^(.*)$ /?Member=$1 [L]
+2  A: 

You can do your prefered method by just adding some lines to the .htaccess in your root directory:

This site should get you started Or this one

Terw
@Terw - thank you for your suggestions. I think your answer is great but it does bring an issue. Let's assume I want www.domain.com/jm4 to actually route to www.domain.com?MemberID=93023893 where both the shortened URL jm4 and member ID of 93023893 are stored on the specific member's database row, I was unable to find any htaccess redirect commands including mysql lookups
JM4
There is no way to access a mysql database in your htaccess. You'd need to have the rule rewrite to www.domain.com?Member=jm4, then use a php script to determine jm4's member id.
Luke
+2  A: 

If you are using apache, then you could use mod_rewrite to change urls like http://host/membername to http://host/memberpage.php?name=membername.

ar
+2  A: 

You could use this in a .htaccess file for your second method. It will rewrite http://yoursite.com/membername to http://yoursite.com/?Member=membername

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /?Member=$1 [L]
</IfModule>
Luke
@luke - while I agree with your code above, I am running into a server error. I have added notes to my original post for my existing .htaccess file which may be causing conflicts?Note: as a test, i replaced the htaccess file as a whole with your code and it did not carry the variable to the necessary page as expected.
JM4
@Luke - the specific apache error I get according to my logs is:[Mon Aug 23 13:42:45 2010] [error] [client 127.0.0.1] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
JM4
I've made a small edit, would you mind testing it again?
Luke
@Luke - the page now redirects to my 404 - does not exist page. Please see my edit above for changes made directly to my existing .htaccess
JM4