Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

419
Views
Setting base_url() in php . What should be the base_url() in any framework of php?

My question not focus on method of how base url is set in any framework of php. Rather what I actually want to know is what should be the base_url() From two options below

  • 1 http://example.com
  • 2 http://www.example.com

Suppose I select option 1 i.e http://example.com all the traffic to my website coming from http://www.example.com will face following problems, similarly if i select option 2 traffic coming from other otpion's url will face problem below.

Problem

Ajax blocked by browsers due to CORS(Cross Origin Request Sharing). Because google treats www and non www requests as from two different websites. My ajax code is below if that can be of any help

$.ajax({
url: '<?php echo base_url(); ?>/Index/perform_task',
type:'POST',
data: {
    name: $("#name_field").val(),
    task: $("#task_field").val(),

},
success:function(data){
    if (data == 'task_completed'){
            window.location.href = "<?php echo base_url() ?>";
        }
        else{
            $('#task_error').html('Some Error occured.')        
        }
}

});

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Are the benefits for any version

The short answer is no. There aren’t any advantages of www or non-www websites because it’s up to personal preference to choose one over another. The main aspect which affects SEO is your consistency, specifically whether you have been adding/removing www to your site’s URL. In order to benefit from this small thing, you need to choose one option and stick to that choice. In short, don’t change your site’s URL when you have already introduced it to well-known search engines.

Otherwise, they will treat both options (www.site.com and site.com) as two different websites and will ban them from doubling pages, keywords, and contents

The only difference between a www and non-www site URL is only a technical one. When your website contains “www.”, it is the hostname which adjusts to DNS and restricts cookies while utilizing other domains. Meanwhile, if your website doesn’t have “www.”, then it doesn’t have such a technical privilege

So what should you do ? Just use one of the version as you like and route all the requests coming to other version to the one you use, and never change it again.

over 4 years ago · Santiago Trujillo Report

0

As @junkfoodjunkie said, you should only use ONE domain and redirect the other. But if, for any reason, you have to keep the two domains, then you should call your ajax script within the current domain.

Then, your base_url() function should return the current domain. for example:

function base_url(){
    return 'http'.(isset($_SERVER['HTTPS'])?'s':'').'://'.$_SERVER['SERVER_NAME'];
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!