you are correct about the .htaccess ; because it is he who controls the distribution and directory names of apache, the server that will compile your php.
To rewrite urls, you need to use htaccess’s rewrite module in this way:
<IfModule mod_rewrite.c>
RewriteEngine On
## diretrizes
</IfModule>
In your example, specifically, you want to change a single URL, in case it would look like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^raiz/public/?([A-Za-z0-9-]+)?$ /raiz/$1 [NC,L]
RewriteRule ^raiz/public/?([A-Za-z0-9-]+)?/$ /raiz/$1 [NC,L]
</IfModule>
In short, anything added in the third level of the root/public will be passed to "/root/TERCEIRO_NIVEL, in the code, the $1 variable
Ok? I hope I’ve helped and it’s important to know that . htaccess is very important for generating friendlier Urls as well as troubleshooting problems like this.
Remember that guidelines change paths in general, so you may need to use the absolute path to generate links from or as an example.
I will add a . htaccess that I use a lot in my web apps, I hope to help
<IfModule mod_rewrite.c>
RewriteEngine On
##sempre utilizar https
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
## URL amigáveis enviando tudo para "site/site.php e diretórios como variaveis link
RewriteRule ^$ site/site.php [L]
RewriteRule ^/?([A-Za-z0-9-]+)?$ /site/site.php?link=$1 [NC,L]
RewriteRule ^/?([A-Za-z0-9-]+)/?$ /site/site.php?link=$1 [NC,L]
RewriteRule ^/?([A-Za-z0-9-]+)/?([A-Za-z0-9-]+)/?$ /site/site.php?link=$1&link2=$2 [NC,L]
RewriteRule ^/?([A-Za-z0-9-]+)/?([A-Za-z0-9-]+)/?([A-Za-z0-9-]+)/?$ /site/site.php?link=$1&link2=$2&link3=$3 [NC,L]
RewriteRule ^/?([A-Za-z0-9-]+)/?([A-Za-z0-9-]+)/?([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ /site/site.php?link=$1&link2=$2&link3=$3&link4=$4 [NC,L]
</IfModule>
## expirar o cache ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## ##
#compactando arquivos
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript text/javascript
</ifmodule>
#End Gzip
# BEGIN Caching
<ifModule mod_headers.c>
<filesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>
<filesMatch "\\.(css)$">
Header set Cache-Control "max-age=604800, public"
</filesMatch>
<filesMatch "\\.(js)$">
Header set Cache-Control "max-age=216000, private"
</filesMatch>
<filesMatch "\\.(xml|txt)$">
Header set Cache-Control "max-age=216000, public, must-revalidate"
</filesMatch>
<filesMatch "\\.(html|htm|php)$">
Header set Cache-Control "max-age=1, private, must-revalidate"
</filesMatch>
</ifModule>
# END Caching
Abs
Lucas, you created the public folder?
– Hiago Souza
Yes, I created the public folder
– Lukas Takahashi
Usually what is left in the public folder is what is exposed on the internet. So your webserver only serves the public, are you running where the application? Apache, IIS.. ?
– Hiago Souza
I’m using the apache
– Lukas Takahashi