ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Output URL without the http://. or the http://www.

August 01, 2012 7:06pm

Subscribe [2]
  • #1 / Aug 01, 2012 7:06pm

    ExpertOrBust

    27 posts

    I was looking for a way to output the domains name without the http://. I know that site_url will do http://example.com but I need it to do example.com. I don’t really want to use a snippet because I’m going to be using this on a large amount of MSM sites. Anyone have a way of accomplishing this?

    Thanks

  • #2 / Aug 02, 2012 6:38am

    Boyink!

    5011 posts

    Snippets can be site-wide, FYI.  So one snippet could be used across all sites in an MSM install.

    Otherwise I wonder if http://devot-ee.com/add-ons/extract-url would work - but I don’t recall the parameters it had.

  • #3 / Aug 02, 2012 6:45am

    ExpertOrBust

    27 posts

    Hi Mike, thanks for responding. I was hoping there was a global variable that I was missing in the docs that I could use. If I created a snippet using the {site_url} variable in the snippet and then used php to strip the http:// to end up with something like example.com… would there be anything wrong for doing it like that. e.g. performance wise?

    Thanks!

  • #4 / Aug 02, 2012 6:47am

    Boyink!

    5011 posts

    How often is that value going to change?

    You’d have to test the performance, but I hate making EE continually have to “make” something that might only ever change once..😉

  • #5 / Aug 02, 2012 6:52am

    ExpertOrBust

    27 posts

    The value will be different for every site. Currently each MSM site uses the header and footer of the default site. The only data that needs to be different is the Google Analytics ‘_setDomainName’ e.g.

    [removed]
    
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-XXXXXXX-1']);
      _gaq.push(['_setDomainName', 'example.com']);
      _gaq.push(['_setAllowLinker', true]);
      _gaq.push(['_trackPageview']);
    
      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s[removed].insertBefore(ga, s);
      })();
    
    [removed]
  • #6 / Aug 02, 2012 7:10am

    Boyink!

    5011 posts

    Ah - I see.

    Possibly this plugin would work:
    http://devot-ee.com/add-ons/url-helper - although if I understand the examples right you’re still getting into PHP which seems like overkill.  But I might be wrong there.

    There’s also http://devot-ee.com/add-ons/current-url-ci - maybe you could hack it to return what you need?

    Were it me I’d probably just use site-specific snippets (or Global Variable even) and call it a day.  Once it’s setup you’d probably never have to touch it again.

  • #7 / Aug 02, 2012 7:13am

    ExpertOrBust

    27 posts

    Sweet, I’ll go that route - thanks Mike!

  • #8 / Aug 02, 2012 9:38am

    Dan Decker

    7338 posts

    Hi ExpertOrBust,

    It looks like Mike helped get you on the right path, thanks Mike!

    Is there anything else I can assist you with?

    Cheers,

  • #9 / Aug 02, 2012 9:39am

    ExpertOrBust

    27 posts

    Nope Mikes tip did the trick! Thanks Dan!

  • #10 / Aug 02, 2012 11:48am

    Dan Decker

    7338 posts

    Hi ExpertOrBust,

    Fantastic!

    If you need anything else, please let us know!

    Cheers,

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases