Redirect a domain to subfolder without changing the URL, but not allowing otherwise?

2

I have the following problem, I have an application with the following structure:

  • app - Folder to store project files as controllers and models.
  • public_html - Stores public documents on the web, such as index, uploads, css.
  • routes.php - Manages the routes of my project, called by index.php in the public_html folder
  • .htaccess - "the problem"

I require that when a user accesses exemplo.com , the request is redirected to my public_html folder, in which case the index.php of that folder would be triggered, and would include the routes.php of the directory in the above level, but not I want the url to be exemplo.com/public_html/index.php .

I also do not want to be able to access the url directly as exemplo.com/public_html , that is, to avoid duplicate URLs like exemplo.com/index.php?pagina=1 and exemplo.com/public_html/index.php?pagina=1 , I would like that when someone does direct access to this page, it is redirected to exemplo.com .

Notes : I use the Apache server in the Debian 8 distribution and I want to make these settings through .htaccess , I have mod_rewrite active and functional.

I did not mention any files from public_html , but I think maybe I'll need settings in .htaccess from there.

I want to implement friendly URLs too.

Could anyone help me solve this problem?

    
asked by anonymous 22.11.2015 / 02:32

1 answer

2

I was able to solve my problem by merging several tips I found on the internet.

RewriteEngine On

# Redireciona as requisições externas na public_html para a raiz
RewriteCond %{THE_REQUEST} \ /+public_html/
RewriteRule ^ / [L,R=301]

# Internamente reescreve a requisição de volta para a public_html
RewriteRule ^(/)?$ public_html/index.php [L] 
    
22.11.2015 / 03:50