Reputation: 659
I'm using the Silex "micro-framework" for routing purposes of my application. I'm currently stuck on how to rewrite the url with .htaccess.
Standard Silex url: localhost/myapp/web/index.php/hello/name
I want it to look like: localhost/myapp/hello/name
With the following .htaccess code, I'm able to omit the /index.php/
part. But I still have to use the /web/
part.
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!
Upvotes: 4
Views: 7636
Reputation: 20286
I've faced the same problem right now and the solution was to change .htaccess content to:
FallbackResource /index.php
So in your case it would be
FallbackResource /web/index.php
This worked for me and I hope someone will find it useful.
Upvotes: 2
Reputation: 1
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>
Upvotes: 0
Reputation: 3368
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>
The right would be to set up your DocumentRoot
to /path/to/your/app/web
.
Upvotes: 1
Reputation: 2277
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]
Upvotes: 0