New page in html

Asked

Viewed 68 times

1

Let’s assume I have a site called site.com.br, and two HTML files. One called index.html, and the other sub.html. I would like to make sure that the index.html file stays on the site as just site.com.br and sub.html stays as site.com.br/sub.html.

How can I do that? Thanks in advance.

  • 2

    It will already look like this by default. Servers, by default, will look for a file called index in the root directory when no file is passed through the URL and when passed, the server will attempt to open the file. Did you have any trouble when you tried to do that?

  • Are you trying to make url friendly? If so, although not the best, use folders. The folder name is the one that will be in the URL and in each folder an index.html Example: site.com/ [index.html] site.com/pagina1/ [index.html (with other content)] site.com/[pagina2/ [index.html (with other content)] site.com/pagina3/ [index.html (with other content)]

  • The default site is this: Index.html the other files will be: URL/page.html

2 answers

1


Gabriel,

By default, every server will identify the file index.html and will reference it as a "home" or home page automatically and any other page would come au end of the address, as /sub.html. It is possible to configure more details and I could give you an example, but for that I would need more information about which server you would be using. I’m waiting for more information to help you better!

  • I’m using Github Pages.

0


I will assume that the site is already on a web server (it can be with localhost).

If the server is Apache it is very easy to resolve this. Just create or modify the file/file .htaccess at the site root (where index.html is located) with the following code:

 RewriteEngine On
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ index.html/$1 [L]

If it doesn’t work I recommend changing the index.html for index php. and thus use the following code in .htaccess:

 RewriteEngine On
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ index.php/$1 [L]

Attention that for this to work it is necessary that the rewrite must be enabled on the server (by default is).
It can also happen that you’re not using Apache and there is already outside my area of knowledge.
I hope I helped :D

  • But this way, for any URL accessed, the file will be displayed index.html and that was not the request. Maybe I misunderstood what the author meant, but normally I would not need to do anything to get the result he wants, see my comment on the question.

  • Dude, you don’t need all that. Just put index.html and sub.html in the server root.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.