Laravel skip directory from framework - php

I am facing a problem, the mapping of my site looks like this:
- app
- bootstrap
- public_html
- archives
- css
- js
index.php
- vendor
composer.json
etc...
My .htaccess is located in public_html. I want to skip the directory public_html/archives from the whole framework. How would I do that? I want the route mysite.com/archives to be accessible outside Laravel.
Edit:
Here is my htaccess file
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteCond %{REQUEST_URI} "/public/archives/" <--- ADDED!
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

As others have noted, Laravel won't process any files or directories that exist because of the following rules:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
First, take this rule out of your .htaccess file:
RewriteCond %{REQUEST_URI} "/public/archives/"
Then, after the RewriteEngine On line, you need to add this rule:
RewriteRule ^archives/?$ - [PT]
So your .htaccess file will look like this:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteRule ^archives/?$ - [PT]
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Alternatively, you can just add the following line before RewriteCond %{REQUEST_FILENAME} !-d:
RewriteCond %{REQUEST_URI} !^/archives/?.*$

Related

File .htaccess in Sub Folder (Wordpress inside Laravel)

I have Wordpress apps inside Laravel. This is what it's looks like.
public
--article
WordPress inside article folder. The reason I do this because I want it to access WordPress like this
{host}/article
There is issue occured. I can access {host}/article/wp-login.php. But when I fill The Login Form out and then send it, I got Laravel 404 Not Found Error Page.
This is weird because several days ago I can do that, but now error occured.
I think I miss some configurations in the .htaccess but I don't know the error.
This is my Laravel .htaccess configuration
# 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]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
and this is my WordPress .htaccess
# public/article/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteOptions inherit
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /article/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /article/index.php [L]
</IfModule>

laravel 5.6 not redirecting properly

I am setting laravel 5.6 in a subfolder but it is giving error the page is not redirecting properly. I have tried everything with the htaceess. I have setup the htacess at the root folder as well as the public folder but it is not working
My root 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]
</IfModule>
and here is my htacess for public folder
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /charity-frontmode/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
Please help! Thanks in advance
Try the following
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]

Redirect to a folder located on laravel installation folder

I have installed wordpress on a sub folder (sricargo-blog) inside the laravel installation folder. I want to redirect to that wordpress folder(admin panel of wordpress) when user click on /wp-blog url. I get this 404 page not found error everytime I go to that url.
This is the directory structure
sricargo
app
bootstrap
config
database
public
resources
sricargo-blog
storage
tests
..
..
..
..
Other laravel files
This is my route in web.php
Route::get('/wp-blog', function () {
return Redirect::to('sricargo-blog');
});
.htaccess file in public folder
<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]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /../sricargo-blog/index.php/$1 [L]
</IfModule>
What am i doing wrong ? Is there a better way to do this ?
You can directly do it using .htaccess, no need to give route in laravel.
In your .htaccess file put this code.
RewriteEngine On
Options Indexes FollowSymLinks
RewriteBase /wp-blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /../sricargo-blog/index.php/$1 [L]

laravel lumen installation inside wordpress installed directory

I have installed WordPress in root directory, I want to install laravel lumen inside a subdirectory. It gives wordpress error " No Page Found!".
I can access files from other directories.
My lumen .htaccess file code 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]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
I have nothing special in wordpress .htaccess file.
What i have to do ?
Update your .htaccess file. Add
RewriteCond $1 !^(YOUR_LUMEN_DIRECTORY)
After
RewriteEngine On
Sample .htaccess rules:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond $1 !^(YOUR_LUMEN_DIRECTORY)
# 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}]

How to remove public/index.php from url in laravel 5?

I am using laravel 5 and having one problem when i upload my project on rackspace it is showing public/index.php in the url. Without this my project is not working.
Please help me .
Htacesss of my public is this :-
<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>
With regards
Harpartapsingh
You do this by making the /path/to/laravel/public folder itself your webroot in Apache/nginx instead of /path/to/laravel. With that, and the standard .htaccess in the public folder, you should be able to access your routes without the public or index.php URL segments.
copy your .htaccess file from your public folder and paste in your root directory
with this code inside .htaccess:
<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]

Categories