Jump to content

Need help with website links


BuddyRangel

Recommended Posts

Need help because my brain is fried and not thinking correctly. :-)

What I am having trouble trying to figure out is this.
I am in charge of real estate websites and what I want to be able to do is shorten up urls within the domain.
For instance: let's say that an agent tells someone to go to their profile and gives them this url - realeastesales.com/johnsmith
When anyone who types this in the address bar I want it to show realeastesales.com/johnsmith and not realeastesales.com/agents/johnsmith/profile.html where the actual profile page is, my questions is what is the best and easiest way to acheive this?

P.S. If this is not to difficult I would like to do this with the whole website, not show the profile page extension i.e. index.html (just show realeastesales.com), contact.html (just show realeastesales.com/contact) etc.

Is there a program that I can use to accomplish this?

Link to comment
Share on other sites

Well having many different html files is not a good start.

Is hard to give you some perfect advice on what you have besides saying you need to make rewrite rules in htaccess or apache itself.

 

To make what you want easier...

Should have more of a dynamic site such as an index.php file and loading different data depending on the GET parameters.

After that could do rewrite rules in htaccess or apache itself. Such as removing GET keys and or values and formatted pretty.

Then can include the directory/file or any dynamic data you are doing.

 

You could even do these as subdomains such as johnsmith.realeastesales.com which could also be the same as realeastesales.com/johnsmith or even realeastesales.com/agents/johnsmith

 

Bear with me as I try to show an example of how I do it.

 

Add a new a record through your domain registrar with  * and the ip

 

Some make a new serveralias in apache under the main virtual host with the servers ip

 

change this:

ServerAlias www.yourdomain.com

to:

ServerAlias *.yourdomain.com

 

 

I do my site by making a simple index file in the root folder.

That index file includes some other scripts needed across entire domain.

One thing it includes is a controller script that examines the GET array and will include different scripts using a switch and ensuring file exists with permissions.

 

Mind you this is my custom cms and in progress, did not even make them pretty urls yet.

http://dynainternet.com/?action=services

 

Through my controller, If the action is set and is in my whitelist I include in this case....services.php

 

controller.php

//whitelist to only allow these GET paramters to pass in code
$allowed_get = array(
    "search",
    "action",
    "user",
    "id",
    "page",
    "preview",
    "q",
    "contact"
);

//loop get requests and remove any unwanted ones
if (isset($_GET)) {
    foreach ($_GET as $key => $value) {
        if (!in_array($key, $allowed_get)) {
            unset($_GET[$key]);
        }
    }
}

//default page displayed if all else fails
$page = "home.php";

/*
loop through action array to determine destination
$action_array located in actions.php, if action value is not in the array it won't load
*/

if (isset($_REQUEST['action'])) {
    if (in_array($_REQUEST['action'], $action_array)) {
        
        switch ($_REQUEST['action']) {
            case "home":
                //$page = "home.php";
                header("Location: ".$server_host);
                exit;
            break;
            case "services":
                $page = "articles.php";
            break;
            case "articles":
                $page = "articles.php";
            break;
            case "help":
                $page = "articles.php";
            break;
	    case "help_post":
                $page = "help_post.php";
            break;
            case "register":
                $page = "register.php";
            break;
            case "account":
                $page = "account.php";
            break;
            case "support":
                $page = "support.php";
            break;
            case "users":
                $page = "users.php";
            break;
	    case "search":
                $page = "search.php";
            break;
	    case "preview":
                $page = "search.php";
            break;
			case "contact":
                $page = "contact.php";
            break;
            default:
                //$page = "home.php";
                header("Location: ".$server_host);
                exit;
        }
        
        
    }
}

//include the page only if it exists
$script = dirname(__FILE__) . DIRECTORY_SEPARATOR . $page;
if (file_exists($script)) {
    require_once($script);
} else {
    header("Location: ".$server_host);
    exit;
}

I have wildcard subdomains set up and rewrite rules.

If the server host name is a subdomain and that user exists, could show just their content, This could be through a users folder using their subdomain/name or including the same template as I did here to return just that users data or site within.

http://quick.dynainternet.com/

 

This actual url is http://*.dynainternet.com/userpage.php the * can be anything and is a wildcard.

I have in my index.php file an if statement to load different content.

You could do this any subdomain directly but I happen to want this just as a content area for my needs.

$directory_path = dirname(__FILE__) . DIRECTORY_SEPARATOR;

if($_SERVER['HTTP_HOST'] != "dynainternet.com"){
require_once($directory_path . "/userpage.php");
}else{
require_once($directory_path . "/controller.php");
}

I have rules to go to exact subdomains for other purposes as well.

This is my http://api.dynainternet.com/ which would be denied access for without the parameters and a public key

Subdomain is a folder in my root directory named api

In my /etc/apache2/apache2.conf file I added virtual host rules for it

<VirtualHost *:80>
        ServerName api.dynainternet.com
        DocumentRoot /var/www/api
        <Directory /var/www/api>
            Options +Indexes
            allow from all
        </Directory>
</VirtualHost>

Could also do domain mapping such as this.

<VirtualHost *:80>
        ServerName videowebcast.me
        DocumentRoot /var/www/videowebcast
        <Directory /var/www/videowebcast>
            Options +Indexes
        </Directory>
</VirtualHost>

Another subdomain I have is called service which is also a folder, that I did through htaccess.

ErrorDocument 404 /
AddDefaultCharset UTF-8
RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS}s on(s)|
RewriteCond %{HTTP_HOST} ^www\.(.+)$
RewriteRule ^ http%2://%1%{REQUEST_URI} [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]


RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} service\.dynainternet\.com
RewriteCond $1 !^service
RewriteRule (.*) /service/$1 [L]

Now to get back to showing how to load specific folders per agent/user.

 

userpage.php

include('db-con.php');
    $user_sql = "SELECT * FROM users WHERE username = '" . mysqli_real_escape_string($con, $this_user) . "'";
    if ($result = $con->query($user_sql)) {
        if (mysqli_num_rows($result) >= 1) {
            while ($row = $result->fetch_assoc()) {
                $username = trim($row['username']);
                echo "<a href='http://" . $_SERVER['HTTP_HOST'] . "'>" . $username . "</a><br />";
            }    
            
            //load site if available
            $site_directory = $directory_path . "/sites/";
            $site_path      = $site_directory . $this_user . "/index.php";
            if (is_dir($site_directory) && is_readable($site_directory)) {
                if (is_file($site_path) && is_readable($site_path)) {
                    require_once($site_path);
                } else {
                echo "No custom site folder, fetch some dynamic data for this user";
                }
            } else {
                echo "Directory doesn't exist";
            }
            //end load site        
        } else {
            echo "No user named " . $this_user . " exists.";
        }
    } else {
        echo "Sorry, Database issue.";
    }
}

Here is 3 different results using the above.

http://demo.dynainternet.com/

http://quick.dynainternet.com/

http://blahblah.dynainternet.com/

 

Now you can take the same idea as above and use header redirects or loading specific folders or agents.

Link to comment
Share on other sites

Sorry I missed a few items on userpage.php

if ($_SERVER['HTTP_HOST'] != "dynainternet.com") {

include('db-con.php');

    $this_user = str_replace(".dynainternet.com", "", $_SERVER['HTTP_HOST']);

    $user_sql = "SELECT * FROM users WHERE username = '" . mysqli_real_escape_string($con, $this_user) . "'";
    if ($result = $con->query($user_sql)) {
        if (mysqli_num_rows($result) >= 1) {
            while ($row = $result->fetch_assoc()) {
                $username = trim($row['username']);
                echo "<a href='http://" . $_SERVER['HTTP_HOST'] . "'>" . $username . "</a><br />";
            }    
            
            //load site if available
            $site_directory = $directory_path . "/sites/";
            $site_path      = $site_directory . $this_user . "/index.php";
            if (is_dir($site_directory) && is_readable($site_directory)) {
                if (is_file($site_path) && is_readable($site_path)) {
                    require_once($site_path);
                } else {
                echo "No custom site folder, fetch some dynamic data for this user";
                }
            } else {
                echo "Directory doesn't exist";
            }
            //end load site        
        } else {
            echo "No user named " . $this_user . " exists.";
        }
    } else {
        echo "Sorry, Database issue.";
    }
} else {
    echo "Display error or redirect";
}
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.