Silex 500 error - mod-rewrite

index.php
use Silex\Application;
require_once __DIR__ . './vendor/autoload.php';
$app = new Application();
$app->run();
htaccess
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
visiting
127.0.0.1/index.php
I get
500 internal error.
Any solutions please?

Your htaccess files should not be named .htaccess.php but just .htaccess.
Then make sure every files have the good rights (apache has access to it).
Be also sure that mod_rewrite is enabled.

Related

Laravel on a shared hosting server returns error 500

I'm using a shared hosting server, I installed my first Laravel 5.4 application and everything is still working fine. A few days ago I installed another Laravel 5.4 application on a different domain, but same server, but when I try to access the URL, I get 500 INTERNAL SERVER ERROR.
Below is my .htaccess code
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
I also tried the following, but same error:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
### Add two lines for fix error 500 ###
Options -Indexes
php_flag xcache.cacher 0
#######################################
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
You moved everything inside your public_html folder which you should not do. Only files inside /public needs to be in public_html, hence the name public. The Laravel files should be placed higher directory where it is not accessible from the public.
Install Laravel with Softaculous, or with composer via SSH in /home/username/laravel
Move everything in /home/username/public_html folder to
/home/username/laravel
Move everything in /home/username/laravel/public to /home/username/public_html and delete the public folder after move.
Edit this file: /home/username/public_html/index.php
Change to require '/home/username/laravel/vendor/autoload.php';
Change to $app = require_once '/home/username/laravel/bootstrap/app.php';
Save this file and close window.
Edit this file: /home/username/laravel/server.php
Change to:
if ($uri !== '/' && file_exists('/home/username/public_html'.$uri)) {
return false;
}
require_once '/home/username/public_html/index.php';
Replace username with your hosting username. :)

Why my .htaccess in codeigniter is different

All of my .htaccess in codeigniter like this
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
But all tutorial .htaccess are like this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
I need help to remove index.php url in codeigniter.
Why should I replace all code .htaccess like tutorial said ?
Should you replace all code .htaccess like tutorial said ?
Yes! just in the root directory of your CodeIgniter project.
Why?
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
The CodeIgniter documentation says that by the rules given in .htaccess file, any HTTP request other than those for index.php, images, and robots.txt is treated as a request for your index.php file.
without these rules, for example, you'll have to access your login page like this
http://yourdomain.com/index.php/<controllerName>/login
with the rules in .htaccess file it's
http://yourdomain.com/<controllerName>/login

500 error after moving site on PyroCMS (CodeIgniter) to other server

I just moved old site of my client to some test server.
The site is on PyroCMS.
I've changed database settings in aplication/config/database.php and changed base_url in aplication/config/config.php to my test site URL.
Unfortunatly site is giving me 500 error and I don't have any error logs to see what else is to change.
Where I have to do changes to site run?
My .htaccess looks like this:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
# NOTICE: If you get a 404 play with combinations of the following commented out lines
#AllowOverride All
#RewriteBase /wherever/pyro/is
# Keep people out of codeigniter directory and Git/Mercurial data
RedirectMatch 403 ^/(application\/cache|codeigniter|\.git|\.hg).*$
# Send request via index.php (again, not if its a real file or folder)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
I use PyroCMS for almost all my clients and the same issue is in the default .htaccess file.
Try to remove:
Options +FollowSymLinks
And try to add:
Options +symlinksifownermatch -Indexes
Options -MultiViews
Many hosting disable +FollowSymLinks for security reason.
Make sure to set 775 permission to:
system/cms/cache
system/cms/logs
addons
uploads
assets
Also make sure to set your env to PYRO_DEVELOPMENT to see all the errors in this debug phase.

Laravel 5.1 rewrite url not working

I am Working on Localhost (WAMP server, php version 5.5.12)
url: http://localhost/laravel/
my root directory .htaccess is:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
Public Directory .htaccess is :
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
In this scenario when I want to access: http://localhost/laravel/
following error message appears:
Sorry, the page you are looking for could not be found.
1/1
NotFoundHttpException in RouteCollection.php line 161:
But when I access : http://localhost/laravel/public/
It successfully loads home page. I have debugged every thing in url rewriting it works fine but laravel not accepting new urls. Can anyone please help me regarding this issue.
You can simply solve this problem. From your public directory index.php file move in root directory like "project-name/index.php"
Then edit your index.php file
In line 22 replace
"require DIR.'/../bootstrap/autoload.php';" this with
"require DIR.'/bootstrap/autoload.php';"
and line no 36 replace
"$app = require_once DIR.'/../bootstrap/app.php';" with
"$app = require_once DIR.'/bootstrap/app.php';"
Now edit autoload.php from "project-name/bootstrap/autoload.php"
here replace line no 17
"require DIR.'/vendor/autoload.php';" with
require DIR.'/../vendor/autoload.php';
now browse your project-name. I think it will solve your problem. You can also laravel development server as localhost:8000 for this open your project folder in command window and type "php artisan serve" hit Enter.

Apache not properly routed for Laravel

I have moved my index.php for Laravel from /public to /public/api. Right now, if I want to access it, I have to type the index.php in the URL as well.
For instance, to access a resource, I have to type localhost/api/index.php/resource otherwise I get a 404 error.
Can someone please help? The .htaccess works fine on my friend's computer who is running a MAC, but it doesn't work on my Windows 8 computer:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /api/
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
I highly recommend that you do not do this as I can see no reason that you should be altering where the index.php file is placed. You will likely run into other issues when making your application as well. With that said you need to modify the index.php file to contain the following lines. Notice the extra ../ since you have moved it up one directory.
require __DIR__ . '/../../bootstrap/autoload.php';
$app = require_once __DIR__ . '/../../bootstrap/start.php';
Also make sure the .htacess file is placed inside the same folder as your index.php file.
I should also note you should not have to modify the .htacess file at all for this. Remove the
RewriteBase /api/
line from your .htacess.

Resources