Question

I know there are SEVERAL similar questions already asked on this topic. I've looked at all of them and none of them have solved my issues. Here's what i have done so far:

  1. Already considered using a Virtual Host (i dont want to, for several reasons)
  2. Made sure mod_rewrite is on (YES, it is!)
  3. written an .htaccess file that contains the default Silex Webserver Configuration. posted [here](http://silex.sensiolabs.org/doc/web_servers.html) and is contained inside silex/ directory. code below
  4. Successfully reached the silex/web/index.php page via localhost/~username/silex (so mod_rewrite is definitely working). code below as well
  5. I echo out a "here!" statement and on silex/web/index.php
  6. I tried one solution that consisted of placing a second .htaccess file in the silex/web/ dir

.htaccess file:

Options -MultiViews
RewriteEngine On
## this was uncommented because silex is in a subdir
RewriteBase /~username/silex/web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

/silex/web/index.php file:

require_once __DIR__.'/../vendor/autoload.php';

$app = new Silex\Application();

echo "HELLO";

$app->get('/', function() {
    return 'Hello!';
});

$app->run();

When I get to the silex/web/index.php here's what I get:

Sorry, the page you are looking for could not be found

I've been working on this for about 2 days now and am starting to lose it. any help will be greatly appreciated. thanks.

Was it helpful?

Solution

AH HA! i found my answer here -> MAMP Silex htaccess.

I'm hoping this solution will help other people from going though my pain! :)

OTHER TIPS

In your .htaccess is missing the rewrite condition for the directory, try this:

<IfModule mod_rewrite.c>
  Options -MultiViews
  RewriteEngine On
  RewriteBase /~username/silex/web
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^ index.php [QSA,L]
</IfModule>

or use

FallbackResource /~username/silex/web/index.php

if your Server is running Apache >= 2.2.16.

Expanding on the solution, you need to create an htaccess for the subdirectory containing Silex (and probably Symfony, etc) and tell Apache how to interpret routes. To paraphrase crzpata's Gist:

<IfModule mod_rewrite.c>
 RewriteEngine on
 #UNCOMMENT next line if silex app root is in a mamp subdirectory
 #RewriteBase /your_mamp_htdocs_silex_app_root
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^ web/index.php [L]
</IfModule>

Then define your silex routes using that defined root:

$app->get('/directory_in_silex_root'...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top