I'm new to the Laravel framework. I am considering learning it and using it for a personal project, but as I am reading through the documentation I see that the web server document root would need to be set to the project folder.
Is it possible to integrate a laravel project with an existing webiste built with PHP and apache? For example, if I have a wordpresss install and wasn't using a framework but wanted tp create a subsite, I could just add more html and php files into a folder somewhere on the existing site or use a different vhost. Not sure if integrating would be so easy with Laravel,though.
Yes, it's possible. The solution I mentioned here should work for you.
To make it work you should modify both Laravel and Wordpress .htaccess files.
Laravel .htaccess example:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
#Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/blog/ # <=== NEW LINE!!!!
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Wordpress .htaccess example:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/ # <==== CHANGED LINE!!
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L] # <==== CHANGED LINE!!!
</IfModule>
Related
I've spent the whole last two days trying to deploy my Laravel React Vite website on Hostinger
I followed The instructions from Hostinger docs as below:
I uploaded my website.
created new .env and add my configs.
created a database.
added build folder from react vite after running "npm run build" to the public folder.
edit resource/view/welcome.blade.php with the build js and css src as below #vite(['public/build/assets/app.a0a7c860.js', 'public/build/assets/app.69041b03.css']).
I have already .htaccess file in public folder which 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]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
it still gives me 403 error Although it works correctly on localhost
I tried to add new .htaccess in the project directory
as below
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
now it gives me 500 server error
I am in doubt that hostinger couldn't recognize my project structure
How to solve that problem?
I have a problem with .htaccess configuration for multiple Laravel projects on my Apache webserver. One project in the root folder and one project in a subfolder
File structure (/www)
/ <-- Laravel application #1
/anotherProject <-- Laravel application #2
When I'm visiting www.example.com/anotherProject then I get a 404 error (and www.example.com is working. The following .htaccess is activate in /public/ (for Laravel application #1).
/public/.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]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
It feels like I need to change something in the .htaccess file of the project in the root folder. Has someone a suggestion to try?
I am trying to install WordPress into Laravel public folder. I have completed the installation, but when I am trying to access the same with URL getting WordPress home page without any design.
Please find the .htaccess files of Laravel
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
#Exclude url with quora
RewriteCond $1 !^(quora)
# 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>
WordPress .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /quora
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /quora/index.php [L]
</IfModule>
Dont put your wordpress folder inside laravel public's folder, it's a wrong way to do it and can cause problem.
I advise you instead to create 2 folders on the server root, one with laravel and one with wordpress.
Then to access to wordpress from laravel you have two choice,
use a subdomain (wordpress.exemple.com)
create an alias (exemple.com/wordpress)
I think what your looking for is the alias so
to create the alias, create a new apache conf but instead of using server property, use alias property
Alias /wordpress /var/www/wordpress/
<Directory "/var/www/wordpress/">
//here your directory conf
</Directory>
enable the conf in apache, restart the server and now, on laravel when you go to the route /wordpress you're on wordpress.
I have my index.php file one directory above framework folder.
So, I have two versions of htaccess file each with its own troubles:
The Laravel friendly htaccess:
Works perfectly for Laravel, but when my link is shared on Facebook, it becomes www.myqourse.com/www.mqourse.com/..../.../... etc.
# Use PHP56 Single php.ini as default
AddHandler application/x-httpd-php56s .php
<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]
</IfModule>
The no issues version for Facebook and Twitter:
Doesn't load resources (.js or .css) but Facebook and Twitter can only get a clean link.
# Use PHP56 Single php.ini as default
AddHandler application/x-httpd-php56s .php
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteRule !^(public/|index\.php) [NC,F]
Any help?
I mistakenly forgot to remove pretender.io from Kernel.php as a global variable 6 months ago. I did it locally, but forgot to push to the server that one particular file :/
I have Laravel installed in /var/www/html
I have a PHP script installed in /var/www/html/i/
The htaccess of /var/www/html/ is
<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]
The htaccess of /var/www/html/i/ is
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.+)$ /?variable=$1
</IfModule>
Trouble is whenever I go to
/i/somevariable
I get a 404 error from my laravel app.
Make a .htaccess file in your root folder with this content:
RewriteEngine On # Turn on the rewriting engine
RewriteRule ^([A-Za-z0-9-]+)/i/?$ index.php/i/?s=$1 [NC,L]
This should work fine.
if you are using apache
read mod_rewrite
http://httpd.apache.org/docs/current/mod/mod_rewrite.html
dont just turn on,
use rewrite rule