Como configurar o mod_rewrite corretamente ao usar o CakePHP?

0

Isso, a princípio, pode parecer uma pergunta duplicada, mas eu fiz 10 horas de pesquisa na Internet e tentei quase tudo que encontrei, mas não tive sorte com a modificação de reescrita. A maioria dos posts / tutoriais na internet são antigos e eles não atualizaram o artigo desde então.

Eu posso ver com phpinfo() , que carreguei com êxito o módulo mod_rewrite .

Em seguida, sei que preciso alterar AllowOverride None para AllowOverride All e poucas alterações no arquivo default.conf do Apache. Como não tenho um arquivo default.conf , fiz essas alterações em 000-default.conf , mas mod_rewrite não funciona. Eu também mudei o arquivo apache.conf , ele ainda não funcionou. Eu mudei todos os arquivos onde eu posso ver <Directory> </Directory> mas não funcionou.

Meu diretório raiz não é /var/www , na verdade, é /var/www/html .

Aqui está o meu arquivo 000-default.conf :

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html

# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf

 <Directory />
        Options FollowSymLinks
        AllowOverride All
 </Directory>

 <Directory /var/www>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order Allow,Deny
        Allow from All
 </Directory>

 <Directory /var/www/html>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order Allow,Deny
    Allow from All
 </Directory>   
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Como posso fazer com que mod_rewrite funcione?

    
por Darin Park 13.09.2014 / 19:59

1 resposta

2

Problema resolvido.É um problema com o CakePHP. O arquivo .htaccess do diretório raiz não estava sendo copiado junto com a fonte CakePHP.

Crie um arquivo .htaccess no diretório raiz do CakePHP com este conteúdo

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

Referência: link

    
por Darin Park 13.09.2014 / 22:49