Internal Server Error 500 laravel ubuntu14.04 - .htaccess

Options -MultiViews
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]
what is wrong?

Make sure you've pointed your web server (Apache) to a public directory, not Laravel root directory.
Also set write permissions on a storage folder:
chmod -R 775 storage

Related

Dynamic RewriteBase based on server

How do I create dynamic .htaccess file that recognizes the server path. It needs to work on localhost folder which path is:
/Library/WebServer/Documents/myscaryproject/.htaccess
and on hosted server path which is:
/domains/mydomain/.htaccess
This is my .htaccess currently:
ErrorDocument 404 /myscaryproject/404.php
RewriteEngine on
# removing index.php from url
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ /myscaryproject/index.php?event=$1 [L]
# removing index.php and replacing it with event and page parameter
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)$ /myscaryproject/index.php?event=$1&p=$2 [L]
RewriteRule ^login/?$ login.php [NC]
This all doesn't work if I push it to the server, because pathing isn't correct.

Removing index.php from url with .htaccess file. The code is in laravel framework

Normally the index.php in laravel framework is in the /public_html/public/ folder.
In my case it is in /public_html folder
This is the code inside my .htaccess file
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
What changment should I make to exclude index.php from urls ?
The code structure is as follows :
/public_html/sitemap.xml
/public_html/sitemap.htm
/public_html/server.php
/public_html/robots.txt
/public_html/readme.md
/public_html/index.php
/public_html/.htaccess
/public_html/public
/public_html/database
/public_html/config
/public_html/cgi-bin
/public_html/bootstrap
/public_html/app
and inside /public_html/public
/public_html/public/web.config
/public_html/public/robots.txt
/public_html/public/favicon.ico
/public_html/public/upload
/public_html/public/js
/public_html/public/img
/public_html/public/css
I highly discourage moving index.php out from the public folder.
I was able to achieve what you are trying to do by following this tutorial.
There, you move your code base out from public_html folder to /appications/your-app folder and move content of public folder into public_html/your-app.
The tutorial is self-explanatory.
I use this Laravel project's structure too (index.php in the project's folder). In my case I did next:
rename server.php in the root folder to index.php
Make .htaccess in the root folder:
Insert this code inside the IfModule mod_rewrite.c
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_URI} !(\.css|\.ttf|\.woff|\.woff2|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(css|js|images|fonts)/(.*)$ public/$1/$2 [L,NC]
After spending hours I write below code for me and its 100% working.
Use this code just after
RewriteEngine On
Redirect index.php to non index.php
RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^index.php/(.*)$ /$1 [R=301,L]

Configure htaccess for Slim Framework

I have this directories structure on my server:
site.com/www/index.php
site.com/www/api/Slim
site.com/www/api/index.php
I want configure Slim for use as rest-api interface in 'api' folder. How can i configure htaccess in api folder for it?
Note. in www/ i have other htaccess and index.php for my project, i think this should not prevent. htaccess in www folder:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ index.php
You need to set your RewriteBase to folder where Slim application is located.
RewriteEngine On
RewriteBase /api/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
This one is the I am using.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]

Using htaccess to remove codeigniter index.php in a subdirectory

I'm trying to remove the index.php from my CI urls, but having followed the instructions it doesn't seem to be working.
I have a codeigniter installation running in a subdirectory. There is a default controller set in the routes config called main, and another controller called 'create'. The default runs fine, but going to /create returns a 324 error saying No Data Received. My htaccess looks like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
This should be enough:
<IfModule mod_rewrite.c>
RewriteEngine On
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
This is what I use. My CodeIgniter also runs in a subdir.
RewriteEngine on
RewriteCond $1 !^(index\.php|images|swf|uploads|js|css|robots\.txt)
RewriteRule ^(.*)$ /ci/index.php/$1 [L]
.htaccess add:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Go into application/config/config.php and clear the index page config value:
// Old
$config['index_page'] = "index.php";
// New
$config['index_page'] = "";
Solved My problem hope others too... :)
Sometimes you need to enable it the rewrite module, run "apache2 enable module rewrite":
sudo a2enmod rewrite
You need to restart the webserver to apply the changes:
sudo service apache2 restart
Then folow Sofia's answer.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
for ubuntu

htaccess for subdomain

Need help with .htaccess
I have website on my localhost with this .htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ website/index.php/$1 [L]
Now i want to move the site to subdomain.domain.com
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://subdomain.domain.com/index.php/$1 [L]
I chaged the url but this doesn'n work maybe because this is subdomain i don't know
hosting details:
# Subdomain Name Path [?]
1 subdomain.domain.com /home/www/subdomain.domain.com
my urls are like this
http://website/index.php/contact
with this htaccess i can use
http://website/contact
When i moved the site to the subdomain i can use http://subdomain.website/index.php/contact but when try http://subdomain.website/contact gives me error
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Try with this one, it should work for all domains localhost as well as server.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
Make sure "rewrite_engine = on" on server.

Resources