I download Silex because I want to try it in my next project. I'm using mamp under Windows 8.1 64x , I think that this doesn't matter but, anyway, I put Silex into C:\mamp\htdocs\projectfolder\ (http://locahost/projectfolder/)
This means that I got http://locahost/projectfolder/vendor and http://locahost/projectfolder/web/
I wrote this .htaccess under "web" directory
Options -MultiViews
RewriteEngine On
RewriteBase /projectfolder/web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
It works perfect if I come into http://locahost/projectfolder/web/hello, but I want to come from /projectfolder/, so I created a new htaccess file in /projectfolder with this content:
Options -MultiViews
RewriteEngine On
#RewriteBase /projectfolder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ web/index.php [L]
But when I run it, the app retun an NotFoundException: Sorry, the page you are looking for could not be found.
Thanks in advance
I'm new to silex too, so if anyone has better insights please tell/teach us :)
I decided to create a project on a separate folder from silex and, what I did was, I created a new index.php requiring silex's autoload.php and a new .htaccess which is basically the same.
So, I have this structure:
/myproject/silex/
/myproject/app/
/myproject/app/index.php
/myproject/app/.htaccess
my .htaccess
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
and my index.php
<?php
require_once __DIR__.'/../silex/vendor/autoload.php';
...
BTW, I configured a vhost to point to /myproject/app/
Hope this helps.
Related
The laravel application seems to have routes issue with the sub-directory on server. With the running application on local machine does not work on temporary domain in sub-directory on live server. Playing around .htaccess seems to have different results.
This question is almost identical to what I would be looking for but he hasn't got any solution while I have got some work around.
The .htaccess within the laravel public have been modified to something like:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteBase /~timely/email-client //<--base has been modified
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
The application will redirect you to host gator 404 page.
Also I've added .htaccess to the main directory which will forward every request to public directory.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Upon removing the home/main .htaccess just works for / route: e.g
http://gator4057.temp.domains/~timely/email-client/public will work but all other routes are redirected to the same host gator 404 page.
Your comments and answers will be appreciated.
Thanks
Step 1. Move all email-client/public to email-client/. Now we're getting somewhere. Warning: Don't forget to copy the .htaccess file too
Step 2. Open email-client/index.php in your favorite editor and change
$app = require __DIR__.'/../bootstrap/app.php';
to
$app = require __DIR__.'/../email-client/bootstrap/app.php';
or may be
$app = require __DIR__.'/email-client/bootstrap/app.php';
and change:
require __DIR__.'/../bootstrap/autoload.php'
to
require __DIR__.'/../laravel/bootstrap/autoload.php'
or may be
require __DIR__.'/laravel/bootstrap/autoload.php'
Run command:
php artisan cache:clear
php artisan config:clear
php artisan optimize
OR
If you dont wana to do more changes try this:
Put this in index.php file
$app->bind('path.public', function() {
return __DIR__;
}
Hope work for you.
I'm trying Silex for first time but I can't get a simple call with a friendly URL to work properly, but if I use a non friendly URL it does it's job. I'm experimenting in localhost and the domain is
localhost/site
and the structure looks like this:
site
|- ...
|- .htaccess
|- /php/
|- rest.php
The .htaccess code:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^rest/(.*)$ php/rest.php/$1 [QSA,L]
</IfModule>
If I try calling
localhost/site/php/rest.php/anything
It works properly and returns the expected value, but if I try this
localhost/site/rest/anything
It just keep saying
No route found for "GET /site/rest/anything"
When the route for it to work must be /anything
I have tried:
Moving .htaccess to /php/.
Changing the RewriteRule to RewriteRule ^ rest.php [QSA,L].
Changing the RewriteBase to RewriteBase /site/php/ and /site/.
Thank you.
I don't actually think this is possible, because Silex doesn't look for the /$1, and can only see what's in your address bar. (Unless the rest.php resides in the directory being requested.)
Your best bet would probably to reconsider your directory structure. If the web root for Silex is the php folder, then the request should be made to localhost/site/php/anything, with the .htaccess file being in that directory.
Alternatively, just rename the php folder to rest, and make sure you use the following rules (.htaccess file saved in the rest directory):
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /site/rest/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ rest.php [L]
</IfModule>
Lastly, you could just define you routes in Silex as site/rest/{anything} without changing your current setup. That is cumbersome, though, which leaves the previous option as the best option.
I have a Silex project. Works on localhost(using php.exe) but I've just transferred it to a subdirectory of an existing website. For example:
www.website.foo/silex/
On the site, because of funky existing routing, the silex app is symbolically linked in the webroot under a /silex/ folder, but is actually elsewhere in the filesystem. The index page works.
I wasn't using an .htaccess file, but I copied the one from the documentation, but it hasn't gotten me anywhere.
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /var/www/webroot/silex/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
I am at a complete loss as to why it doesn't work, let alone what to change to fix it.
Edited .htaccess
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /silex/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Question
Does the .htaccess file have to be in the root directory? Or is being in the application directory fine?
Your RewriteBase directive is wrong, its related to web root, not your filesystem structure, so just use RewriteBase /silex/
I need to publish my web app written in laravel 4,
i've followed many tutorial in internet but i'm not able to make it works correctly.
i'm on a dedicate server with centos 6.6 where resides another website so the laravel app should be placed in a sub folder named vols
this is the current folder structure:
/
var/
www/
laravel/
app/
bootstrap/
vendor/
...
html/
vols/
other files of my website
i've changed the paths inside bootstrap/paths.php to
'app' => __DIR__.'/../../laravel/app'
'public' => __DIR__.'/../../html/vols'
'base' => __DIR__.'/../../laravel'
'storage' => __DIR__.'/../../laravel/app/storage'
and the paths inside vols/index.php to
require __DIR__.'/../../laravel/bootstrap/autoload.php';
$app = require_once __DIR__.'/../../laravel/bootstrap/start.php';
my first controller is named volunteers, so if visit http://mydomain/vols i should be redirected to http://mydomain/vols/volunteers
instead i see this error message: The requested URL /vols/volunteers was not found on this server.
if i try to connect to http://mydomain/vols/index.php/volunteers everything works correctly but i don't want index.php in my route.
i think i should work on .htaccess inside vols folder, but i've never studied how it really works, so i'm just copying some random snippets from internet substituting public with vols.
currently it look like this
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^vols
RewriteRule ^(.*)$ vols/$1 [L]
</IfModule>
Some solutions suggests to create vhost, technically i can do that, but i don't know how.
Could you please help me?
You should place the following .htaccess in your vols folder -
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /vols/
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
For some reason when I deploy my API using Restler's API Explorer (a fork of Swagger UI) to production it gives me a general 404 error when I load:
/api/explorer
When I am more explicit and state:
/api/explorer/index.html
It loads the framing for the page but then reports "404 : Not Found ../resources.json" in red text below the header:
I'm fairly certain there's something environmental flaring up as the same files locally work. I also checked the .htaccess file in the /api/explorer directory and it looks right to me:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ index.html [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.html [QSA,L]
</IfModule>
Any help would be appreciated.
It turns out all the problems were down to a mod_rewrite problem. I'm still not 100% on WHY this problem showed up in one environment but not others with precisely the same httpd.conf and .htaccess. Oh well, the solution is to be explicit in the rewrite rule about your base url using the RewriteBase directive.
In the API directory I now have the following .htaccess file:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /api
RewriteRule ^$ index.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
In the API-Explorer directory I now have the following .htaccess:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /api/explorer
RewriteRule ^$ index.html [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.html [QSA,L]
</IfModule>
In order to troubleshoot this problem one invaluable tip that I came across is turning on Apache's mod_rewrite logging.
# Adding logging for Rewrites
RewriteLog logs/rewrite.log
RewriteLogLevel 2
Put this in any globally scoped area of httpd.conf; I put it around the entries that were already there about logging but you can also just put it at the end if you like that better. In addition, the basics around rewrite troubleshooting includes (apologies if this basic):
make sure that your httpd.conf has AllowOverride All and Options FollowSymLinks set for the directories you serving Restler out of.
You can put all of the configuration into httpd.conf and avoid .htaccess files altogether (and it's a bit faster that way too) but if you do that remember that httpd.conf has absolute url referencing versus .htaccess's relative.
You can check the ReadMe file on the Restler Github page
https://github.com/Luracast/Restler-API-Explorer#readme
Did you add the 'Luracast\Restler\Resources' class to create resources.json at API Root?
In your own index.php, the addAPIClass section should look like this:
$r = new Restler();
$r->addAPIClass('Luracast\\Restler\\Resources'); //this creates resources.json at API Root
// ... your own addApiClass
$r->handle();
It is in the documentation under "Use", but I had trouble figuring this out as well...
Make sure you have cache directory with write permission in your api root