0

When my simple apache webserver hits index.php it redirects to index.html however in the url instead of rooturl.com its example.com/index.html. Is there a simple way to fix this?

header( 'Location: /index.hmtl') ;

www.example.com

5
  • This sounds like a server configuration problem, not a PHP programming issue. Commented Sep 12, 2019 at 3:50
  • This php file is the first thing the server hits when someone navigates to my domain. It routes the user to this URL. I still want the redirect but without the filename in the url Commented Sep 12, 2019 at 3:52
  • You mean header("Location: /"); ? Commented Sep 12, 2019 at 3:53
  • Sorry if im not explaining myself correctly. This PHP file is the entry point. I have two index files with different languages that get redirected based on browser language. I want the redirect to happen without the file name tact on the end. Commented Sep 12, 2019 at 3:53
  • That won't work if the server defaults to index.php when there's no filename, since you'll just keep redirecting to the PHP file. You have to put a filename if you want it to redirect to a different page. Commented Sep 12, 2019 at 3:54

1 Answer 1

1

There can only be 1 default directory index file. Either http://example.com/ resolves as http://example.com/index.html or http://example.com/index.php. You can't have both work at the same time.

Instead of redirect to different index.html for different language, I think you should consider to directly include the HTML file. For example,

<?php

// index.php
switch (some_get_user_language_func()) {
  case 'en':
    include './index.en.html';
  case 'es':
    include './index.es.html';
  case 'fr':
    include './index.fr.html';
  default:
    include './index.en.html';
}

Alternatively, you may try Apache's mod_negotiation to switch HTML file without the index.php file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.