When I open the site with the server.php file, my index page is displayed (index.blade.php), and the link on that page to the list page (list.blade.php) opens successfully. I encountered issues with it recognising my javascript files when I access via server.php? However if I open the public folder it puts me at my index page and javascript files are recognised...
When I open the public folder, and I click the list link I get "Sorry, the page you are looking for could not be found."
web.php
Route::get('/', function () {return view('index');});
Route::get('list', 'IngredientsController#display');
IngredientsController
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Ingredient;
class IngredientsController extends Controller
{
/* Displays list of ingredients in db */
public function display()
{
$ingredients = Ingredient::all();
return view('list', compact('ingredients'));
}
}
ingredient.php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Ingredient extends Model
{
}
link on index page to list page: List url
htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# 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>
Laravel doesn’t use the root for including the files. So yes your IDEA see your files includes correctly but laravel it doesn’t.
See this post answer:
https://stackoverflow.com/a/28915577/5334073
Laravel uses the public folder as the ‘root’ folder. That’s just how Laravel works. To call that root you should use the URL::assets function as explain the the answer from the post I gave you.
Above RewriteEngine On I put Options +FollowSymLinks and above RewriteRule ^ index.php [L] I added RewriteBase /nameoflaravelproject/public/
I added these two lines of code and it works. Sorry I dont really understand this so if someone can explain to provide a better resource for other users then thats great.
Related
why my laravel url not working when method is post
example the url api must be : http://localhost/PROJECTNAME/api/loginWeb
but when i click post button it always direct to http://localhost/api/loginWeb
but when method is get this okay. i use xampp
here is my htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# 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>
When we're using session based laravel setup, all the route generator functions(url(), route()) use hostname http://localhost as root url, not http://localhost/PROJECTNAME. To resolve this issue please do following changes in laravel app.
Define APP_URL in .env file as APP_URL="http://localhost/PROJECTNAME"
Go to RouteServiceProvider which is located at app/Providers/RouteServiceProvider and force laravel to use APP_URL as root url for your app.
public function boot()
{
parent::boot();
// Add following lines to force laravel to use APP_URL as root url for the app.
$strBaseURL = $this->app['url'];
$strBaseURL->forceRootUrl(config('app.url'));
}
Same issue occurred to me when I used same domain and a suburl to identify different projects.
Linux: Nginx serves multiple apps with two different locations
Windows: Multiple Laravel Applications Using Nginx - Windows
I am about to deploy a laravel project. I uploaded all the files and the website is working fine but the only problem is when i try to access my website i.e for example if i try to write mywebsitename.com in the url then public directory is shown which is because i have symblinked my laravel's public folder to the public_html folder. I don't have any idea about how to edit the .htaccess file in order to load the website with mywebsitename.com and not mywebsitename.com/public. My htacess files code is
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# 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>
my file directory structure is shown in this image
please help me
I am guessing it is an apache server. If yes;
Ensure your domain mywebsitename.com points to the public_html
Add a .htaccess file in your root directory(public_html) and paste this in
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
I found a solution to this question.
1.Copy all the laravel files inside the public_html folder including the .htaccess file and the index.php file which is suppose to be inside the public folder(keep both the files inside the public folder).
2.Then link your storage to the public folder using SSH, for that open your SSH enter id and password and change directory using "cd domains/yourdomainname.com/public_html"
then give the php artisan command i.e "php artisan storage:link"
(note:- after changing the directory you can give all the php artisan commands like migrate and config:cache or clear:cache as you wish.
3.Now after the all the necessary commands are given you can access your fully functional website including the image display function if you type yourdomainname.com/public on the URL but if you type just your domain name then all the laravel files will appear on the browser to avoid this and to to jump inside the public folder directly create one more .htaccess file outside the public folder but inside the
public_html folder the copy the below given code and then if you just your domain name on the URL then your website will be directly displayed
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteRule ^ public [L]
You can use it with RewriteBase directive,
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteBase /public_html/ # or '/' only depends on your vhost config
# 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>
I'm not familiar with apache server but the problem should be in the default index file.
For long terms considered, I advise you to use nginx or openresty, it's easier to configurate.
I wish to remove the index.php in the url of a laravel 4.2 site. But i don't know how to do that. Without index.php/ the pages are not loading. My routes.php contains
Route::get('/', 'HomeController#home');
Route::get('login','HomeController#home');
Route::get('forgotpassword', 'LoginController#ForgotPassword');
Route::post('loginprocess', 'LoginController#loginprocess');
Route::group(array('before' => 'auth'), function()
{
Route::get('locations','LocationController#locations');
Route::get('createlocation','LocationController#createlocation');
Route::post('createlocation','LocationController#savelocation');
Route::get('editlocation/{data}','LocationController#editlocation');
Route::post('editlocation/{data}','LocationController#updatelocation');
Route::get('deletlocation/{data}','VendorController#deletevendor');
Route::post('statusactiveLocation/{data}','LocationController#statusactiveLocation');
Route::post('statusinactiveLocation/{data}','LocationController#statusinactiveLocation');
Route::get('vendors','VendorController#vendors');
Route::get('createvendor','VendorController#createvendor');
Route::post('createvendor','VendorController#savevendor');
Route::get('editvendor/{data}','VendorController#editvendor');
Route::post('editvendor/{data}','VendorController#updatevendor');
Route::get('deletevendor/{data}','VendorController#deletevendor');
Route::post('statusactiveVendor/{data}','VendorController#statusactiveVendor');
Route::post('statusinactiveVendor/{data}','VendorController#statusinactiveVendor');
Route::get('logout', 'LoginController#Logout');
});
Try this...
To remove the “index.php” suffix from the end of your Laravel applications url, use one of the two methods below.
This also works for removing the public from your url
Method1.
At the minimum use the following code and put it in your “public” folder inside an htaccess file. Make the public folder the root of your application.
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Method2.
If you do not have access to change you application’s root folder to public, put the following code in your application’s root directory(which presumably is the one where public is contained in) inside of a .htaccess file.
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ public/index.php [L]
I'm working in my first project with Laravel, it's a simple website with an admin panel:
In my "public" folder I have a directory called "admin" where I put all the styles and scripts corresponding to the admin panel. I've also defined a route in my app to handle the "admin" GET:
Route::get('/admin', 'Admin\DashboardController#index');
The problem is that since I have that "admin" folder in my public directory Laravel is ignoring the "admin" route I defined, so I can't access the proper controller. I'm suspecting it has something to do with the .htaccess but I'm not sure how to solve it. This is how my htaccess looks right now:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
The issue is with the following line:
RewriteCond %{REQUEST_FILENAME} !-d
In your example this tells the web server not to send the /admin route to Laravel because it is a physical directory. If you remove that then the /admin route should work. This will however prevent browsing directly to a folder and getting a directory listing, which should not be a problem. The next line in the htaccess will allow you to link to asset files contained in your admin directory and not have them get processed by Laravel, so that should not be removed.
The newer version of Laravel also contains:
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
It should be updated to the following in order to avoid a redirect loop on the admin route:
# Redirect Trailing Slashes...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
So if using the newest version of Laravel, your htaccess file should look something like this:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
You cannot have a public directory with the same name as your route - otherwise how will Laravel know whether "/admin" is for the controller, or for the style etc.
You should store your admin style sheets etc under /assets/admin/*
For routes.php:
Route::controller('admin/dashboard', 'Admin\DashboardController');
For using assets in your public container you can now use:
<script type="text/javascript" src="{{Request::root();}}/assets/js/jquery.js"></script>
Where assets in the /public/assets/js/jquery.js
Hope this helps.
Hi all I am new to CodeIgniter framework. I tried to develop a page which contains a form.
Here is the view
<?php echo form_open('Site/check');?>
User Name: <?php echo form_input(array('id'=>'Username' ,'name'=>'username' ,'class="input-medium " ')); ?>
Add User:<?php echo form_submit('submit','Add User','class="btn btn-primary"');?>
<?php echo form_close();?>
This is the controller
<?php class Site extends CI_Controller{
function login() {
$data['records']="BHOOM!!!";
$this->load->view('login',$data);
}
function check() {
$this->load->view('showmessage');
}
}
?>
The showmessage is a PHP page with a hello in <h1> tags.
I already googled and searched for similar issues, but I didn't get any resolution
The base url is localhost/ci/index.php
Error
Unable to load the requested file: showmessage.php
.htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|js|css|img\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
Here is a tutorial straight from EllisLab. Follow steps and you will get your form working.
The most common mistakes,
not loading form helper
htaccess. is set wrong, or paths are wrong (capital letters etc.).
config.php is not set properly
not passing data to view ($this->load->view('some_view', $data);
Hence you did not provide us error message if one exists there is no possible help from the community.
For more debug info please turn on codeigniters profiler ($this->output->enable_profiler(TRUE);), use PHPs native function var_dump($variable);.
Make sure error reporting is set to E_ALL in your index.php
edit
Make sure your /config/config.php
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = "";
make your .htaccess this file should be located in root of your project eg. /ci/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ci/
# Reenable after getting ssl cert
# RewriteCond %{HTTPS} off
# RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
# Removes access to the system folder by users
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
# When your application folder isn't in the system folder This snippet prevents user access to the application folder
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
# 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
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's can be sent to index.php, and everything works as normal.
ErrorDocument 404 /index.php
</IfModule>
just use this type of code for your trial
view
<?php
echo form_open('controllet_name/method_name');
form_input(array('id'=>'Username' ,'name'=>'username' ,'class="input-medium " '));
form_close();
?>
controller
()
{
$name=$this->input->post('username');
echo $name ;
}
I think your RewriteRule is wrong.
Try:
RewriteRule ^(.*)$ /ci/index.php/$1 [L]