Silex slugs cause 404 page not found - php

Following the documentation, Silex allows "slugs" to be passed in via the URL for use within your code.
The following example works:
$app = new Silex\Application();
$app->get('/', function () {
return 'HAI';
});
However, the following gives a 404 Not Found:
$app = new Silex\Application();
$app->get('/{slug}', function ($slug) {
return 'HAI' . $slug;
});
How can I fix this 404?
In case it's of any relevance, here's my Apache Vhost:
<VirtualHost 127.0.0.1:80>
DocumentRoot "/var/www/Silex/web"
DirectoryIndex index.php
<Directory "/var/www/Silex/web">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
...and my directory structure:
/src
|-- bootstrap.php
/tests
/vendor
/web
|-- index.php

It turns out that this was an Apache issue. It was assumed that you could either use a .htaccess file, or a vhost. You actually need to use both.
.htaccess:
FallbackResource /index.php
Note: You can only use FallbackResource if using Apache 2.2.16 or higher.
vhost
<VirtualHost 127.0.0.1:80>
DocumentRoot "/var/www/Silex/web"
DirectoryIndex index.php
<Directory "/var/www/Silex/web">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
An alternative is to place the contents of the .htaccess file (the FallbackResource directive) within the vhost itself, and get rid of the htaccess.
As soon as I added the .htaccess, the slug in my second example worked.

Related

Missing POST and GET with Apache Alias

I have a Symfony project with the file index.php in /var/www/public.
I want to only allow access to the website using a virtual generate folder, so the site should always be accessed like this: http://localhost/generate.
http://localhost/ should just throw a 404.
I'm using the following Apache config, but the $_POST and $_GET globals are missing when I debug my script (I'm firing a POST request from Postman). It works when I reset my Apache config to just serve from the root without any alias..what is going on?
I'm not using any .htaccess files in my /var/www/public folder.
The Apache config:
<VirtualHost _default_:80>
ServerAdmin webmaster#localhost
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<FilesMatch ".+(\.php)$">
SetHandler "proxy:fcgi://127.0.0.1:9100/
</FilesMatch>
DocumentRoot "/var/www/public"
Alias /generate /var/www/public
<Location /generate>
AllowOverride All
</Location>
</VirtualHost>
Since you are using Symfony, you can simply define routes for /generate and nothing for /
routes.yaml
Generate:
path: /generate
controller: ControllerNamespaceAndName::MethodName
Because you don't use route definition for / when accessing http://localhost/, symfony's kernel will throw a 404

How to remove public from the URL of Laravel project?

I've followed this and this answers to remove /public form the URL of my Laravel project. Now /public is removed from the URL. But my IDE (phpstorm) is throwing an error:
Does anybody know how can I fix it?
Note: I use Laravel 5.4
Change your apache vhost / host document root to projects public folder. its realted to apache config.
<VirtualHost *:80>
ServerName findexample.com
DocumentRoot c:/xampp/htdocs/find_people/public
<Directory c:/xampp/htdocs/find_people/public>
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/find-people-error.log
CustomLog ${APACHE_LOG_DIR}/find-people-access.log combined
</VirtualHost>
See how to setup apache vhost on windows
You dont need to touch on any file to get what you want.
Try setting your document root to
path/to/your/laravel_app/public/
If your root is pointing to your public folder, when you access it from Browser, you will not need to use public in the url.
Remember that you must enable ModRewrite.

Internal Server Error Slim and .htaccess

First I need to say ya sorry for my bad english
I hope u can help me strangers.
I have created a domian in my linux Debian 8.
look it
<VirtualHost *:80>
ServerAdmin admin#admin.com
DocumentRoot "/var/www/saci"
ServerName saci.com
ServerAlias www.saci.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/var/www/saci">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I'm using slim and I've created a folder named 'app' on the folder 'saci' with a file start.php that got this:
<?php
use Slim\App;
session_cache_limiter(false);
session_start();
ini_set('display_errors', 'On');
define('INC_ROOT', dirname(__DIR__));
require INC_ROOT . '/vendor/autoload.php';
$app = new App();
$app->get('/test', function() {
echo "this is a test.";
});
?>
Now on my folder saci I've created a folder named Public with one index.php and one .htaccess.
so now look my roots
Var > www > saci > public
index.php <------------------index daaa
.htaccess <------------------.htaccess
var > www > saci > app
start.php <----------------start
so now my problem is here
I've got an index.php with this
<?php
require '../app/start.php';
$app->run();
and a .htaccess with this
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
but when I go to my host www.saci.com I can see my index of/
with all my proyects folders But I cannot see the folder public, and if I go to www.saci.com/public
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at admin#admin.com to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Apache/2.4.10 (Debian) Server at www.saci.com Port 80
I rly DON'T HAVE IDEA of what is going wrong I need rly rly help
starting now
Thanks Steangers U rock never forget smile
Greetings from Venezuela

Slim Framework routing doesn't work in my code

I'm new to this, I have a problem with following code:
<?php
require_once 'vendor/autoload.php';
require_once 'lib/controller/Root.php';
require_once 'lib/controller/General.php';
$app = new \Slim\Slim(array(
'debug' => true,
));
$root_controller = new Root();
$general_controller = new General();
$app->map('/', function() use ($app, $root_controller) {
$root_controller->index();
})->via('GET', 'POST');
$app->map('/vorstand', function() use ($app, $general_controller) {
$general_controller->vorstand();
})->via('GET', 'POST');
$app->map('/satzung', function() use ($app, $general_controller) {
$general_controller->satzung();
})->via('GET', 'POST');
$app->run();
?>
I'm using the slim framework and I can't call the routes localhost/vorstand or localhost/satzung everytime I get "Not found" And I have no explanation for that :/ only localhost which means the route "/" works.
For Apache server, two things need to be check.
1.The .htaccess file in the directory (same directory with your index.php) contains:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
2.You also need a directory directive to enable .htaccess files and allow the RewriteEngine directive to be used. This is sometimes done globally in the httpd.conf file, but its generally a good idea to limit the directive to just your virtual host by enclosing it in your VirtualHost configuration block. This is generally setup in your configuration in the form of:
<VirtualHost *:80>
ServerAdmin me#mysite.com
DocumentRoot "/path/www.mysite.com/public_html"
ServerName mysite.com
ServerAlias www.mysite.com
#ErrorLog "logs/mysite.com-error.log"
#CustomLog "logs/mysite.com-access.log" combined
<Directory "/path/www.mysite.com/public_html">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Add AllowOverride All to your DocumentRoot Directory.

Apache alias directive

I am trying to set up simpleSAML.php but I am running into an issue with the Apache Alias directory. I have successfully used Alias so that when the user visits domain.com/auth then it uses the folder /var/saml/www.
However, for some reason it just lists the contents of the folder /var/saml/www rather than running the index.php file.
I have included the relevant virtual host below.
<VirtualHost *:80>
ServerAdmin helpdesk#domain.com
DocumentRoot /var/www/html/open
ServerName open.domain.com
ErrorLog logs/open.domain.com-error_log
CustomLog logs/open.domain.com-access_log common
Alias /auth/ /var/saml/www
Alias /auth /var/saml/www
<Directory /var/saml/www>
Options All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
You can add the following line to your config:
AddType application/x-httpd-php .php
This way apache knows it has to parse the files using php.
P.S. I think you may have to restart Apache rather than a reload.
Update
As Alfabravo commented:
Agree. He also needs to check the DirectoryIndex directive and add index.php to it

Categories