I have created my application using laravel and vue.js and hosted my application on server in subfolder inside public_html,
Accessing it using url like this:
https://maindomain.in/projectfolder/public/login
but after login if i click on any link it points back to
https://maindomain.in/dashboard
and i get 404 not found in console for the api routes that are accessed for eg. accessing dashboard
https://maindomain.in/api/backend/get-dashboatd-data
My root htaccess file content is :
<IfModule mod_rewrite.c>
RewriteEngine on
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
# Force SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Remove public folder form URL
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Note: Frontend is in Vue.js and backend in laravel.
Any help is highly appreciated
It seems to me like your web server is not pointing to the right folder.
Laravel expects you to serve the project from the public folder inside the project's root directory.
You're serving it from the main apache/nginx folder. That's why you need to add the subfolder and public folders in the URL to visit the website.
Check the Laravel Nginx configuration example to notice the root directory they're specifying.
Your nginx/apache server is configured wrong
You must point nginx/apache to the folder
/var/www/XXX_PROJECT_XXX/
Related
I have a Laravel 5.2 application on a cPanel hosting account in which I had to remove the "public" folder from the URL with the following .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Now I need to redirect everything incoming to just the main domain/page www.example.com to be redirected to www.example.com/en.
I tried some examples but all of them break the local css and img.
Reinventing the wheel is always a bad idea. What you should do is to setup your web server correctly by pointing it to a public directory and restarting it. Also, use original Laravel .htaccess.
After that use Laravel localization.
Then you could just copy Controller#method you using for /en route and put it into / route.
I'm new with codeigniter and right now I'm trying to migrate a codeigniter application to another server. This application was in another server and now I want to move it to another server. In this server I have also a wordpress website and it works perfectly.
Firstly, what I have done it's a backup from the mysql database and from the files and I have move them via ftp to the another server under the /inventarios folder, so if I wrote on my browser
http://xxxxxx.com/inventarios
I should see the codeigniter application but what I receive it's a 404 error with the Wordpress interface
I have change the database.php and the another files from the config folder and it doesn't work. Why?. Under the inventarios folder I don't have a .htaccess file. Could you help me,please?. Thanks and let me know if you need more details.
EDIT 01
The htaccess which I have in the root folder is this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I don't know if inside of inventarios I should place another htaccess.
Thanks so much
Create sub-folder with name of inventarios in root of your host. Inside the folder upload all your CI folders(application, system, index....).
Then go to application/config/config.php
$config['base_url'] = 'http://xxxxxx.com/inventarios';
Also /application/config/database.php is to be edited
application/config/config.php
application/config/database.php
Don't forget to update .htaccess in root if there're some updates or url redirects to old domain/url
I currently use laravel 5 for web development. And my goal is to upload the website which I made in laravel to a shared host.
But if I upload my files to the public_html folder, I'll have to navigate to mywebsite.com/public/mypage to access a route mypage. Which is not what I want.
I would have just changed the the name of public folder to public_html and then shifted all other folders to the root directory and changed some laravel config options, but that would have made my root directory unclean. So think I would have to use .htaccess for what I want. I am not familiar in using .htaccess, so how would I do this:
If the user enters mywebsite.com/mypage in the browser he gets to see the page mywebsite.com/public/mypage in the browser, but the url in the browser stays the same.
Thanks, in advance.
I also got the same problem when hosting my website in shared hosting godaddy.
I also used laravel5 frameowork and launched the site http://www.hahafunnyjokes.com
Edit the .htaccess file in the root folder where your public_html pointing
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.examplecom/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Thats it, I got my site up and running.
Replace example.com with your website name
I've searched through Web to solve my problem but non of the solutions works for me there, so after couple of hours of struggling with Routing module I've decided to ask you for a helping hand.
Problem
I am unable to access Laravel application from outside /public directory. I need to type localhost\projects\laravel\public in my browser but what I want is to use the URL withour /public. The main reason is because I use shared hosting and have no access to apache configuration file so I'm unable to create vhost.
Background
I've installed manually Laravel framework under the: **c:\xampp\htdocs\projects\laravel** and used composer to do the rest for me.
The routing has been set to: Route::get('/', 'HomeController#showWelcome');
In my project root directory **c:\xampp\htdocs\projects\laravel** I've put a .htacces file with the following content:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /projects/laravel/
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
In my Application Root dir c:\xampp\htdocs\projects\laravel\public I have .htaccess with the following code in it:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
When I type: localhost\projects\laravel\ I've got NotFoundHttpException
When I type: localhost\projects\laravel\public I've got welcome page
Any help would be appreciate, Thanks.
Finally I've got this thing working. There are two solutions that can be made.
One requires to move all -public content level-up
Second requires slightly changes in your shared hosting directory root structure - if allowed
Solution #1
The first that works for me that I didn't want to implement has been posted by #Wasim in this thread: Laravel 4 removing public from URL The solution is not save as the content core structure is in the same directory as application itself. This could cause some problems in future implementation.
You need to move all the content from public/ folder one level-up into project ROOT directory then replace internal paths in index.php file for correct onece. For security reasons this .htaccess file needs to be put into project ROOT directory
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Modified Laravel structure described above can be uploaded to your shared web hosting and the application should runs withour /public in yor http address.
Solution 2 (with no access to http.conf file on your shared hosting)
This solution does not requires form you to move the content of the /public folder one level-up but requires form you to have read and write access to ../ROOT directory in your shared hosting (../ROOT directory mostly contains public_html, public_ftp and other folders).
You need to move Laravel scructure into ../ROOT directory as follows:
app/
bootstrap/
vendors/
public_html/
public_ftp/
(...)
Files form /public folder goes to public_html
public_html/index.php
public_hmtl/.htaccess
public_html/packages/
(...)
Then modification for /bootstrap/paths.php is required for line with 'public' key:
'public' => DIR.'/../public' to 'public' => DIR.'/../public_html'
If someone has similar issue and this solution does not work please let me know, thanks.
If you want without public on uri, using composer from your laravel root. Use command php artisan serve and browse localhost:8000 from your browser. It will bring you to homepage.
Where did you get this line from?
RewriteRule ^(.*)$ public/$1 [L]
It's not part of Laravel. Try removing it or the whole .htaccess file in your Laravel root.
Hello I am new to laravel and i know laravel has new version but i am using version 3.
Now all i need to do is directly access public folder without typing /pulic in url.
I have placed below .htaccess file in laravel root but it giving me 404 error.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
and i want to do this using .htaccess not using virtualhost.
I think you should make your site's document root point to public from your server config (vhost on apache, not sure what it's called on nginx)