Silex routing.htaccess webroot

I use Silex's "micro-framework" for routing purposes of my application. I am now obsessed with how to rewrite a URL using .htaccess.

Silex standard URL: localhost/myapp/web/index.php/hello/name

I want it to look like this: localhost/myapp/hello/name

With the following .htaccess code, I can omit the /index.php/ part. But I still need to use the /web/ .

 RewriteEngine On RewriteCond %{THE_REQUEST} /myapp/web/index.php/ RewriteRule ^/myapp/web/index.php/(.*) /myapp/$1 [R=301,L] RewriteCond %{REQUEST_URI} !/myapp/web/index.php/ RewriteRule ^(.*)$ /myapp/web/index.php/$1 [L] 

Any suggestions? Thanks!

+4
source share
4 answers

I ran into the same problem right now and the solution was to change the contents of .htaccess:

 FallbackResource /index.php 

So in your case it will be

 FallbackResource /web/index.php 

It worked for me, and I hope someone finds it useful.

+2
source

From: http://silex.sensiolabs.org/doc/web_servers.html

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

It would be more correct to configure DocumentRoot on /path/to/your/app/web .

+1
source

Something like this should do the trick:

 RewriteEngine On RewriteBase / RewriteRule ^myapp/web/index.php/ /myapp/ [R=301,L] RewriteRule ^myapp/ /myapp/web/index.php/ [L] 
0
source

I had a similar problem solved with the following

 <IfModule mod_rewrite.c> Options -MultiViews RewriteEngine On RewriteBase /web RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)? index.php/$1 [QSA,L] RewriteRule ^/?$ /web/ [R=301] </IfModule> 
0
source

All Articles