Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

416
Visualizações
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.')        
        }
}

});

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

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.

about 4 years ago · Santiago Trujillo Relatório

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'];
}
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda