1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to get current url without http:// or www

Discussion in 'Programming' started by Irfi0009, Mar 13, 2011.

  1. #1
    Hi i just wondering if this possible to get current url without http:// and www.
    My site is http://www.wallpapersuper.com but i want to echo wallpapersuper.com
    If this is possible in html please let me know

    Thanks,
    Dellingter
     
    Irfi0009, Mar 13, 2011 IP
  2. RamCity

    RamCity Peon

    Messages:
    732
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Check with your hosting provider. This is related to your hosting.

    Or you can try 301 redirect through your page coding also.
     
    Last edited: Mar 13, 2011
    RamCity, Mar 13, 2011 IP
  3. DocuMaker

    DocuMaker Active Member

    Messages:
    427
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    60
    #3
    In php, you'll have to use string parsing. Plenty of info on the net about that. In html, you'll have to use javascript string parsing. Plenty of info on the net about that too.
     
    DocuMaker, Mar 13, 2011 IP
  4. gtk29

    gtk29 Member

    Messages:
    519
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #4
    Simple Javascript :
    var str = window.location.href;
    document.write(str.replace("http://www.", ""));
     
    gtk29, Mar 13, 2011 IP
  5. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #5
    
    <?php echo str_replace('www.','', $_SERVER['SERVER_NAME']);?> // wallpapersuper.com
    
    PHP:
    Will echo out your domain name, whether it contains www. or not.

    You may also need to edit or create a .htaccess file and add a line of code, which tells your server to parse .html files as if it was a .php file.
     
    Last edited: Mar 14, 2011
    MyVodaFone, Mar 14, 2011 IP
  6. NLZ13

    NLZ13 Well-Known Member

    Messages:
    166
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    113
    #6
    The best thing for SEO is in any way to allow ONLY with OR without www, not both.
    Make a .htaccess file and place it in your public_html folder with the following content:
    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^www.(.*?).([a-z]+)$ [NC] 
    RewriteRule (.*) http://%1.%2/$1 [R=301,L]
    Code (markup):
     
    NLZ13, Mar 14, 2011 IP
  7. Irfi0009

    Irfi0009 Banned

    Messages:
    17,584
    Likes Received:
    33
    Best Answers:
    1
    Trophy Points:
    48
    #7
    I'm Asking about programming in php how we can get current url...You are telling me something about hosting first you need to read thread carefully.
     
    Irfi0009, Mar 14, 2011 IP
  8. Irfi0009

    Irfi0009 Banned

    Messages:
    17,584
    Likes Received:
    33
    Best Answers:
    1
    Trophy Points:
    48
    #8
    If i got my answer over the internet then why should i am here ?i find Some php coding but thats not working thats why i am here coz i did not find a real answer of my question.
     
    Irfi0009, Mar 14, 2011 IP
  9. listiaclone.com

    listiaclone.com Member

    Messages:
    164
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    26
    #9
    <?php
    
    $url="http://www.your-domain.com/"; //place your domain here
    
    // get host name from URL
    preg_match("/^(http:\/\/)?([^\/]+)/i",$url, $matches);
    $host = $matches[2];
     
    // get last two segments of host name
    preg_match("/[^\.\/]+\.[^\.\/]+$/", $host, $matches);
    echo "Output: {$matches[0]}\n";
    ?>
    Code (markup):
    hope this will help you.
     
    listiaclone.com, Mar 14, 2011 IP
    OaldDesign likes this.
  10. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #10
    With regards to my post above, here's a sample of what you need to put in to a .htaccess file. If you dont have a .htaccess file on your server create one and upload it to your root/ directory ie: public_html, www, or htpdocs folder....

    
    AddType application/x-httpd-php .html
    
    
    PHP:
     
    MyVodaFone, Mar 14, 2011 IP
  11. epixeltech

    epixeltech Peon

    Messages:
    148
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    var strurl = window.location.href;
    document.write(strurl.replace("http://www.", ""));

    you need to make once common URL for all Pages it will help you for SEO.
     
    epixeltech, Mar 14, 2011 IP
  12. zaza13

    zaza13 Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    I use this code to get the full URL

    
    function selfURL(){
    list($prot)    = explode('/',strtolower($_SERVER['SERVER_PROTOCOL']));
    $s            = $_SERVER['HTTPS'] == 'on' ? 's' : '';
    $port        = $_SERVER['SERVER_PORT'] == '80' ? '' : ':'.$_SERVER['SERVER_PORT'];
    return $prot.$s.'://'.$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
    }
    echo selfURL();
    
    Code (markup):
    I got that here http://asdlog.com/Get_URL_of_current_page

    Since this is not what you want you can change it like this

    
    function selfURL(){
    $url = $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
    return str_replace('www.','',$url);
    }
    echo selfURL();
    
    Code (markup):
    And it won't echo www. and anything in front of it.
     
    zaza13, Aug 13, 2012 IP
  13. deepakrajput

    deepakrajput Member

    Messages:
    234
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    46
    #13
    You need to edit your website htaccess files to do such a task.
     
    deepakrajput, Jun 20, 2015 IP
  14. Jufcy8200

    Jufcy8200 Banned

    Messages:
    286
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    78
    #14
    You can also try this :D

    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
    
    or
    
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
    
    RewriteCond %{HTTPS} on
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
    
    
    PHP:
     
    Jufcy8200, Jun 24, 2015 IP
  15. Steellayes

    Steellayes Member

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #15
    hi xyz
     
    Steellayes, Feb 21, 2018 IP