Showing posts with label Seo. Show all posts
Showing posts with label Seo. Show all posts

Wednesday, October 13, 2010

How to create subdomains using htaccess?

First, you should set all subdomains to one directory in your web server config.

like this one below: 
ServerName  mydomain.com
ServerAlias   *.mydomain.com
Second, add this code to your .htacess file

RewriteEngine on
# SUB DOMAINS
RewriteCond %{http_host} !www\.([a-z0-9-]+)\.([a-z0-9-]{2,5})$ [NC]
RewriteCond %{http_host} ^(www.)?([a-z0-9-]+)\.([a-z0-9-]+)\.([a-z0-9-]{2,5})$ [NC]
RewriteRule (.*) /clients/%2/$1 [L]
# /SUB DOMAINS 


Finally, you should create a /clients/ folder in the main directory. Now every folder under /clients/ folder is a subdomain
For ex. If you have a test/ folder under the /clients/ folder, you can call the folder test.mydomain.com


How to change URL without refreshing?

You can change the URL without refreshing  with  location.hash  .

For ex: facebook and twitter use this method.

http://twitter.com/#!/username

Browsers use the # symbol as page anchors and you create your own prefix to catch the URL like #!
You can  listen to URL with  window.onhaschange  to send a XHTTP request when it changes.

Example:
<script type="text/javascript"> 
window.onhashchange = function() {
    var link = location.hash.replace('#!','');
// add  your XHTTP request code here
    alert('URL changed. Your link is "'+ link +'"');
}
</script>
<a href="#!/en/home/">change url</a>

If you wish to check browsers' onhaschange capability, you can use the code below:


<script type="text/javascript">
if ("onhashchange" in window) { alert('location hash is enable!'); } 
</script>