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 5 of 5
  1. #1
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts

    Can I use rewrite to create virtual sub-domains ?

    Hi,

    Can I use mod rewrite to create virtual sub-domains ?

    What I mean is, if someone comes to my site
    with fish.example.com

    can mod_rewrite redirect them to:
    example.com/store/search.php?prod=fish

    There are no real sub-domains on my example.com

    Thanks


    .
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,851
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    There are some threads even in this forum, related to your question. Have a look at http://www.google.com/search?q=site%...rite+subdomain
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts
    OK - thanks for the advice.

    I have gone away and done some stuff that should work.

    My .htaccess reads:
    PHP Code:
    Options +FollowSymLinks 
    RewriteEngine On

    # BELOW IS STUFF TO BLOCK SPAMMING ATTACKS 
    ######################################################
    # Block out any script trying to set a mosConfig value through the URL
    RewriteCond %{QUERY_STRINGmosConfig_[a-zA-Z_]{1,21}(=|%3D) [OR]

    # Block out any script trying to base64_encode crap to send via URL
    RewriteCond %{QUERY_STRINGbase64_encode.*(.*) [OR]

    # Block out any script that includes a <script> tag in URL
    RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3E) [NC,OR]

    # Block out any script trying to set a PHP GLOBALS variable via URL
    RewriteCond %{QUERY_STRINGGLOBALS(=|[|%[0-9A-Z]{0,2}) [OR]

    # Block out any script trying to modify a _REQUEST variable via URL
    RewriteCond %{QUERY_STRING_REQUEST(=|[|%[0-9A-Z]{0,2})

    # Send all blocked request to homepage with 403 Forbidden error!
    RewriteRule ^(.*)$ index.php [NC,L]
    #
    ######################################################

    RewriteCond %{HTTP_HOST} ^([^.]+).my-gigs.net [NC]
    RewriteCond %{HTTP_HOST} !^www.my-gigs.net [NC]
    RewriteRule ^.*$ /index.php?cdz=%[QSA,L
    Then on my "index.php" page :

    PHP Code:
    if(isset($_GET["cdz"])){   
        
    $the_key $_GET["cdz"];
        
    $the_key=$the_key."php";
        
    header("Location: /$the_key");
        exit();
        }  
    // end if 
    I also added a "A" Record to my DNS records:
    * A - IPv4 Address 65.xx.xxx.xxx

    BUT, when I enter : mobilewebsite.my-gigs.net
    into my browser I get this:

    The browser goes to this:

    reviewsworthreading.com/wp-signup.php?new=mobilewebsite.my-gigs.net

    Now reviewsworthreading.com is a multiuser network worpdpress site which also has in its domain a wildcard A Record.

    Both domains are on the same sever and on the same IP address.

    I suppose it not surprising that things are getting a bit muddled ?

    But is there a solution ?
    I could ask my server supplier for a new IP address.

    Any thoughts ?


    .
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #4
    New Coder
    Join Date
    Nov 2011
    Posts
    88
    Thanks
    4
    Thanked 26 Times in 26 Posts
    My thoughts would be:

    1: a specific DNS entry for the subdomain to get it to the right server. It looks like that is all in order:

    Code:
    dig +short mobilewebsite.xxxxxxx.net
    xx.xx.xx9.163
    dig +short xxxxxxx.net
    xx.xx.xx9.163
    2: The ALIAS directive on your APACHE virtual host will need to catch your virtual subdomains 'mobilewebsite' [and any others you are using], otherwise requests will drop through to the default site.
    An UNTESTED example vh config:
    Code:
    <VirtualHost *:80>
    DocumentRoot /var/www/sitename/htdocs
    ServerName  sitename.com
    ServerAlias mobilesite.sitename.com subdomain2.sitename.com subdomain3.sitename.com
            <Directory />
                    Options FollowSymLinks
                    AllowOverride None
            </Directory>
            <Directory /var/www/sitename/htdocs>
                    Options -Indexes FollowSymLinks MultiViews
                    AllowOverride All
                    Order allow,deny
                    allow from all
            </Directory>
            ScriptAlias /cgi-bin/ /var/www/sitename/htdocs/cgi-bin/
            <Directory "/var/www/sitename/htdocs/cgi-bin">
                    AllowOverride All
                    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                    Order allow,deny
                    Allow from all
            </Directory>
            ErrorLog /var/log/apache/error.log
            CustomLog /var/log/apache/access.log combined
    </VirtualHost>
    I don't know what your server hosting set up is, or if you can edit the Apache configs directly. If you can't you can probably find some control panel option for adding subdomains which, with a little creativity, can be used or tricked into doing what you want.

  • #5
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Thanks for those insights.

    I will look into the use of alias' that could be the answer


    .
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.


  •  

    Posting Permissions

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