I have a site that when accessed, you're redirected to index.php
page, but in fact I want it to be redirected to the inicio.html
page. How can I change this?
I have a site that when accessed, you're redirected to index.php
page, but in fact I want it to be redirected to the inicio.html
page. How can I change this?
By default, when the browser makes the request, the index.html
file of the requested site is returned. In this case, thinking that you want a response that solves the problem, in that scope specifically, use in the file .htaccess
:
DirectoryIndex inicio.html
Since your file is in root, along with the Apache configuration file, .htaccess
, you are saying that the directory index will be called inicio.html
, and it should be loaded instead of index.php
.
If you want to change the general configuration of Apache, to always search for inicio.html
, instead of default, index.html
, you need to change the settings of the% . Here's the same line of code:
DirectoryIndex inicio.html
However, if you want to use friendly URLs, I'd advise you to read the question that already covers as well the subject, as well as the search for
If you are looking for 301 and 302 redirection, and do not change the% s home page, please read this answer .
I wanted it when I accessed my site, that person was redirected to startup.html. - Robson
If you understand, you want to redirect even when accessing something like http://meusite.com
it will direct to http://meusite.com/inicio.html
.
You have two options, the 301 redirect, which is the permanent redirect:
Redirect 301 / http://meusite.com/inicio.html
Temporary redirect:
Redirect 302 / http://meusite.com/inicio.html
Permanent redirection will cause the user's browser to ignore /
and search engines will not index the /
since it considers both the same URL, inicio.html
is the new address, already in 302 is temporary, both URLs still exist, but technically /
will be temporarily unavailable and therefore it will be pointing to inicio.html
, I believe you want 301.
Note that files with .html
extension will not execute .php
"embedded" scripts inside it if you want inicio.html
to be php
, but with .html
extension, in addition to redirection, you can use mod_rewrite in your .htaccess
, like this:
#direciona / ou index.php (que estejam na raiz) para inicio.html
Redirect 301 / http://meusite.com/inicio.html
Redirect 301 /index.php http://meusite.com/inicio.html
#Ativa o Rewrite
RewriteEngine On
#Ao acessar http://meusite.com/inicio.html será exibido o conteudo index.php
#mas você poderá escrever conteudos no '.php'
RewriteRule ^inicio\.html$ index.php [L]
Now if you want all scripts to have the .html
extension in the URL, but you still use the server side% with , you can use this:
#direciona / ou index.php (que estejam na raiz) para inicio.html
Redirect 301 / http://meusite.com/inicio.html
Redirect 301 /index.php http://meusite.com/inicio.html
#Ativa o Rewrite
RewriteEngine On
#qualquer url que tiver a extesão '.html' irá acessar um .php, mas o usuário irá ver como .html
RewriteRule (^|/)([^/]+)\.html$ $2.php [L]
For example, if you access this .php
on the server side it will run http://meusite.com/foo.html
, but the user will see in url foo.php
, so you can write dynamic pages in PHP and show% p>
If you are using Apache, open the httpd.conf file and change the line DirectoryIndex
to:
DirectoryIndex inicio.html index.html index.htm
In this way, the default file Apache will fetch will be inicio.html
.
If this file does not exist, then it will look for a file named index.html
(the default), and so on.
If you do not find any files, you will list the contents of the directory if this is allowed.
Alternatively, you can put the same directive in the .htaccess
file, as explained in another answer.
The difference is that by changing the file, its setting is valid for the "scope" of the file. Generally only your domain or directory.
Changing in Apache, the setting is valid for all domains.
The change in the .htaccess
file will always overwrite the Apache configuration.