Had to do a local dev system rebuild on my laptop running OSX, installed same Apache/2.4, PHP/5.6.27, and Phalcon/2.0.7 packages. Server code appears to be working correctly aside from routing (and .htaccess code is correct and adding to _url appropriately)
Original routing code:
$di->set('router', function(){
$router = new \Phalcon\Mvc\Router();
$router->add("/{controller}/{id:\d+}", [ "action" => "index",]);
return $router;
}
That route previously worked for all URIs, from /user (show user list), to /user/1234 (view user), to actions like /user/do_action/1234. I never addressed routing more in-depth since that route just worked. The code as is also is working in production (I'm mirroring the libraries used in production, and am getting different behavior locally, but I'm also not seeing what else could be different that's causing the divergent behavior).
Upon local reinstallation, those paths no longer work, defaulting everything as if it was just /index/index. I can't figure out why that route no longer is appropriate, considering I'm using the same Phalcon/Apache/PHP/etc versions as before (and in production).
In terms of workarounds, I'm trying more explicit paths. These work:
$router->add("/user", ['controller' => 'user','action'=>'index']);
$router->add("/user/index", ['controller' => 'user','action'=>'index']);
However no dynamic routing methods work (anything with regex, placeholder, variables):
$router->add("/user/:action", ['controller' => 'user','action'=> 1 ]);
$router->add("/:controller", [ "controller" => 1, "action" => "index",]);
$router->add("/{controller}", [ "action" => "index",]);
$router->add("/user/{id:[0-9]+}", ['controller' => 'user','action'=>'index', ]);
I've done a ton of research on this and nothing makes sense, other than it appears the variables/regex are a common problem. I don't mind writing a script to generate all possible routes by scanning the Controller files, but that would still require the {id:\d+} to work to pull ID numbers, but that's a nonstarter at this point.
I have also verified PCRE is installed and working (Phpinfo shows php was compiled with --with-pcre-regex and is enabled, library version 8.02 2010-03-19.)
Thank you in advance! I also tried upgrading to the newer Phalcon/3.0.1 and see the same routing issues. I figured I'd try and solve it in 2.0.7 since that's where production is currently, and I'll save that other upgrade for another day.
EDIT 1: Including httpd.conf and httpd-ssl.conf
# httpd.conf
ServerRoot "/usr/local/opt/httpd24"
Listen 8080
LoadModule authn_file_module libexec/mod_authn_file.so
LoadModule authn_core_module libexec/mod_authn_core.so
LoadModule authz_host_module libexec/mod_authz_host.so
LoadModule authz_groupfile_module libexec/mod_authz_groupfile.so
LoadModule authz_user_module libexec/mod_authz_user.so
LoadModule authz_core_module libexec/mod_authz_core.so
LoadModule access_compat_module libexec/mod_access_compat.so
LoadModule auth_basic_module libexec/mod_auth_basic.so
LoadModule socache_shmcb_module libexec/mod_socache_shmcb.so
LoadModule reqtimeout_module libexec/mod_reqtimeout.so
LoadModule filter_module libexec/mod_filter.so
LoadModule mime_module libexec/mod_mime.so
LoadModule log_config_module libexec/mod_log_config.so
LoadModule env_module libexec/mod_env.so
LoadModule headers_module libexec/mod_headers.so
LoadModule setenvif_module libexec/mod_setenvif.so
LoadModule version_module libexec/mod_version.so
LoadModule ssl_module libexec/mod_ssl.so
LoadModule unixd_module libexec/mod_unixd.so
LoadModule status_module libexec/mod_status.so
LoadModule autoindex_module libexec/mod_autoindex.so
<IfModule mpm_prefork_module>
</IfModule>
<IfModule !mpm_prefork_module>
</IfModule>
LoadModule dir_module libexec/mod_dir.so
LoadModule alias_module libexec/mod_alias.so
LoadModule rewrite_module libexec/mod_rewrite.so
<IfModule unixd_module>
User me
Group staff
</IfModule>
<Directory "/Users/me/app/www">
Options Indexes FollowSymLinks
Require all granted
AllowOverride All
</Directory>
ServerAdmin [email protected]
ServerName localhost
<Directory />
AllowOverride none
Require all granted
</Directory>
DocumentRoot "/usr/local/var/www/htdocs"
<Directory "/usr/local/var/www/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.php
</IfModule>
<Files ".ht*">
Require all denied
</Files>
ErrorLog "/usr/local/var/log/apache2/error_log"
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "/usr/local/var/log/apache2/access_log" common
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/usr/local/var/apache2/cgi-bin/"
</IfModule>
<IfModule cgid_module>
</IfModule>
<Directory "/usr/local/var/apache2/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
<IfModule mime_module>
TypesConfig /usr/local/etc/apache2/2.4/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
</IfModule>
<IfModule proxy_html_module>
Include /usr/local/etc/apache2/2.4/extra/proxy-html.conf
</IfModule>
Include /usr/local/etc/apache2/2.4/extra/httpd-ssl.conf
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
LoadModule php5_module /usr/libexec/apache2/libphp5.so
AddType application/x-httpd-php .php
httpd-ssl.conf
# httpd-ssl.conf
Listen 443
SSLCipherSuite HIGH:MEDIUM:!MD5:!RC4
SSLProxyCipherSuite HIGH:MEDIUM:!MD5:!RC4
SSLHonorCipherOrder on
SSLProtocol all -SSLv3
SSLProxyProtocol all -SSLv3
SSLPassPhraseDialog builtin
SSLSessionCache "shmcb:/usr/local/var/run/apache2/ssl_scache(512000)"
SSLSessionCacheTimeout 300
<VirtualHost dev.myserver.com:443>
Options Indexes FollowSymLinks MultiViews
DocumentRoot "/Users/me/app/www/"
ServerName dev.myserver.com:443
ServerAdmin [email protected]
ErrorLog "/private/var/log/apache2/myserver-error_log"
CustomLog "/private/var/log/apache2/myserver-access_log" common
<Directory "/Users/me/app/www/">
RewriteBase /Users/me/app/www/
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
Options Indexes FollowSymLinks
Require all granted
AllowOverride All
</Directory>
TransferLog "/usr/local/var/log/apache2/access_log"
SSLEngine on
SSLCertificateFile "/usr/local/etc/apache2/2.4/dev.myserver.com.crt"
SSLCertificateKeyFile "/usr/local/etc/apache2/2.4/dev.myserver.com.key"
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory "/usr/local/var/apache2/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
BrowserMatch "MSIE [2-5]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
CustomLog "/usr/local/var/log/apache2/ssl_request_log" \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
</VirtualHost>
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^((?s).*)$ index.php?_url=/$1 [QSA,L]
</IfModule>
It's about your apache configuration for 100%. But you didn't provided it. You can check this for instance - https://docs.phalconphp.com/en/latest/reference/routing.html#uri-sources