-2

From http://localhost/ I want to access http://localhost/1.php

How can I make it so I can access the 1.php file in the browser without changing the url?

user7282
  • 5,106
  • 9
  • 41
  • 72
123
  • 101
  • 2

3 Answers3

1

Use DirectoryIndex 1.php in your .htaccess file

Peter Kota
  • 8,048
  • 5
  • 25
  • 51
  • I have more than 1 file, I don't want to make my 1.php the index file. – 123 Oct 17 '15 at 15:22
  • 1
    @Lurrdock can you give us some other examples so we can understand what you want ? – Ghilas BELHADJ Oct 17 '15 at 15:27
  • I just want to access that file without changing the url. How can I explain this? When I want to click and open the 1.php file from http://localhost/ I want to open it and the URL to be still http://localhost/ – 123 Oct 17 '15 at 15:31
0

You could use AJAX to get content of different PHP files and display that on your landing page

Nenad Mitic
  • 577
  • 4
  • 12
  • Simplest way is to use jQuery JavaScript library. Then you can make something like this: `$.get('1.php').done(function(data) { $('#content').html(data); });` I'm assuming there's an element with ID "content" on you HTML – Nenad Mitic Oct 17 '15 at 16:57
0

Here a simple example: index.html page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
    <title>Ajax example</title>
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <script src="https://code.jquery.com/jquery-1.11.3.min.js" type="text/javascript"></script>
    <script>
        $(document).ready(function(){
            $("#page1").click(function(){
                $('#result').load('page1.html');
            }); 

            $("#page2").click(function(){
                $('#result').load('page2.html');
            });
            //and so on
        });
    </script>
</head>

<body>
    <ul>
        <li><a id="page1" href="#">One</a></li>
        <li><a id="page2" href="#">Two</a></li>
        <li><a id="page3" href="#">Three</a></li>
    </ul>
        <div id="result" style="clear:both;">
    </div>
</body>

</html>

Assume you have page1.html with the content

<h1>Hi this is page1</h1>

The click on link "one" will fill the div with content of page1.html and so on

Whit this type of implementation you should factory the other pages without header and meta.

Thesee
  • 161
  • 5