Как удалить public из url


To создавая небольшое приложение, и у меня есть url - /root / public/index.php, хотел бы знать, как удалить это public и оставить url-адрес только /root / index.php, используя ..htaccess уже искал в Google, и я нашел только примеры, связанные с laravel, и ни один не работает.

Author: Lukas Takahashi, 2019-04-30

2 answers

Вы правы, о .htaccess ; ибо он-тот, кто контролирует распределение и классификаций, каталогов, apache, сервер, который будет скомпилировать php.

, Чтобы переписать url-адреса, вы должны использовать модуль перезаписи в htaccess, таким образом:

<IfModule mod_rewrite.c>
  RewriteEngine On      
## diretrizes      
  </IfModule> 

В вашем примере, в частности, вы хотите изменить один URL-адрес, в данном случае, будет выглядеть следующим образом:

 <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> 

Краткой форме все, что добавляется в третий уровень/root / public передается "/root/TERCEIRO_NIVEL, в коде переменная $1

Ok? Я надеюсь, что помог, и важно знать, что .htaccess является очень важным для создания Url-адреса, а также решения таких проблем.

Помните, что правила меняются пути, как правило, то, возможно, вам нужно будет использовать абсолютный путь для создания ссылок, или как пример.

Я Буду добавлять .htaccess, который я использую в моих веб-приложений, я надеюсь, поможет

<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

 4
Author: Leonardo Negrão, 2019-05-02 18:03:42

, Основанной в ответ Леонардо, я нашел код ниже, который решает проблему.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^raiz$ [NC,OR] RewriteCond %{HTTP_HOST} ^raiz$
RewriteCond %{REQUEST_URI} !raiz/public/
RewriteRule (.*) /raiz/public/$1 [L]
 2
Author: Lukas Takahashi, 2019-05-02 18:15:19