This is the url I have: link
But I wish it were like this: link does not work file not found
I'm trying on nginx with the following settings
server {
listen 80;
client_max_body_size 100M;
server_name cursophp.test www.cursophp.test;
root /home/rafaelejosi/www/projetos/cursophp.test/;
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location /lojavirtual {
index index.php;
try_files $uri $uri/ /lojavirtual/index.php?$query_string;
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?pag=$1 last;
}
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log on;
error_log /var/log/nginx/cursophp.test-error.log error ;
rewrite_log on;
error_page 404 /index.php;
sendfile off;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
location ~ /\.ht{
deny all;
}
location ~ /*.tpl {
deny all;
}
}
Is there anything wrong with the code snippet?
location /lojavirtual {
index index.php;
try_files $uri $uri/ /lojavirtual/index.php?$query_string;
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?pag=$1 last;
}
}
The weakness of my project is like this
Myphpfilessofarareinthecontrollerandmodeldirectoriesoutsidetheindexandapagesketchoferrorsthatareloose.Butfornowthosewithrelevantcodeareinthemodelfolder.InthemodelfolderIhaveRoutes.class.phpandTemplate.class.php.
belowisthecontentoftheroutes:
<?phpClassRotas{staticfunctionget_pagina(){if(isset($_GET['pag'])){$pagina='controller/'.$_GET['pag'].'.php';echo$pagina;if(file_exists($pagina)){include$pagina;}else{include'erro.php';}}}}
Templatefilecontents:
<?phpClassTemplateextendsSmarty{function__construct(){parent::__construct();$this->setTemplateDir('view/');$this->setCompileDir('view/compile/');$this->setCacheDir('view/cache/');}}
Contentsofmyindexfile
<?phprequire"./lib/autoload.php";
$smarty = new Template();
Rotas::get_pagina();
$smarty->assign('NOME','RAFAEL DIAS ZENDRON');
$smarty->display('index.tpl');
Ja the htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?pag=$1 [L,QSA]
</IfModule>
<Files *.tpl>
Order deny,allow
Deny from All
</Files>
As I do not have much knowledge in nginx I used a converter that converts apache to nginx
nginx error report cursophp.test-error.log
2018/05/31 23:11:41 [error] 20478#20478: *5 FastCGI sent in stderr:
"Primary script unknown" while reading response header from upstream,
client: 127.0.0.1, server: cursophp.test, request: "GET
/lojavirtual/carrinho HTTP/1.1", upstream:
"fastcgi://unix:/run/php/php7.2-fpm.sock:", host: "www.cursophp.test"
cursophp.test.access.log
2018/05/31 23:11:41 [error] 20478#20478: *5 FastCGI sent in stderr:
"Primary script unknown" while reading response header from upstream,
client: 127.0.0.1, server: cursophp.test, request: "GET
/lojavirtual/carrinho HTTP/1.1", upstream:
"fastcgi://unix:/run/php/php7.2-fpm.sock:", host: "www.cursophp.test"