Remove index.php from url in Laravel 5.4 - CentOS 6 - linux

I have tried almost all the solutions on internet regarding this issue.
I have moved my Laravel project from Windows 10 to linux CentOS 6. I tried to change project structure in two different manner but both face the issue.
I am trying to remove index.php from [www.example.com]/index.php/[routes url]. I don't have access to root or sudo command as this project is being installed in University server. But I can request IT admin for tasks that require root access.
I am currently in /home/cs4/username (folder). My current project structure is:
blog (folder)
- contains all the Laravel framework files other than public folder
public_html (folder)
- contains all the files of laravel public folder plus
- .htaccess file created
.htaccces file contains below code:
# Redirect Trailing Slashes...
#RewriteRule ^(.*)/$ $1 [L,R=301]
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^ index.php [L]
RewriteRule ^(.*)$ /index.php/$1 [L]
I have replaced 2 lines of index.php file which is in public_html folder
from these
require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
to
require __DIR__.'/../blog/bootstrap/autoload.php';
$app = require_once __DIR__.'/../blog/bootstrap/app.php';
Issue is that http://example.ac.uk/~username/ loads the project but for all other url's I have to add index.php for example: http://www.example.ac.uk/~username/index.php/login instead of http://www.example.ac.uk/~username/login similarly for all other url's.
I also tried to put entire project inside public_html folder, the directory structure was:
public_html
-entire project files and folders
-public folder
but then 2 issues:
all the server files like : .env and other code is exposed causing security risk
I am forced to have public/index.php in the url.
for example: http://www.example.ac.uk/~username/public/index.php/login instead of http://www.example.ac.uk/~username/login similarly for all other url's.

Related

Is there a way to properly redirect or rewrite vistors in my drupal 8 website to a subfolder?

I have the following code in my .htaccess file:
RewriteEngine on
RewriteCond %{HTTP_HOST} mysitedomain\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /web/$1 [L]
I'm currently using CPanel and CPanel does not allow you to set a new Document Root. So have my drupal files in my CPanel "public_html" directory with the composer.json files etc..and web directory that has all the Drupal related files. I am trying to get the site vistors to rewrite or redirect to www.mysitedomain.com/web for subsequent pages.. I tried the code below but does not seem to work.. Am i missing something?
To be specific.... I need the site to 1. load www.mysitedomain.com/web when www.mysitedomain.com is requested. 2. And ensure /web is is front of every subsequent request page request within the site (ie. www.mysitedomain.com/web/products should load instead of www.mysitedomain.com/products)
I am not sure what your question is, but I think you need something like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
What it does: If the URL does not resolve to a file or directory in the present directory, put index.php in front of it.
I'd assume your index.php would then include the Drupal framework.

How to point my domain directly to a codeignter folder?

Let's say I have a domain www.example.com
Now I want that, at this domain, my index page or main controller of the CodeIgniter folder should open without the folder name and the rest controller pages also without the folder name.
From: www.example.com/folder
To: www.example.com
I am hosting my files on hostinger. I don't want to remove my folder and export all the structure to base public_html.
I want my public_html to contain my CodeIgniter folder.
Any help would be appreciated!
To setup codeigniter on a subdirectory, you could try the following htaccess rule :
Options +FollowSymLinks
RewriteEngine On
RewriteBase /YOUR_SUBFOLDER
RewriteRule ^$ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ index.php?/$1 [L]
Change the YOUR_SUBFOLDER above to whatever subdirectory name you have.

Codeigniter 4: Access the application from main folder

My application structure is like:
wamp/www
/project
/app
/public
/system
/writable
I am able to access the application from http://localhost/project/public. However, http://localhost/project shows index of project.
I tried putting .htaccess file in the project folder.
RewriteEngine On
RewriteBase /project/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ public/index.php/$1 [L]
It is also not working.
How do I make the application accessible from the project folder.

Contents of application folder not accessible in codeigniter

I am not able to access the files(images, css) inside my application and root folder of codeigniter. I have checked the permissions and the links. Everything seems to be fine but it gives a 404 error when trying to load the file. I even tried to load the link directly. All files seems to be loading from the assets but not from the root or application folder.
.htaccess file :
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
I am not sure what direction to look in.
As a matter of fact they were working fine few days back, I haven't made any changes in the htaccess file.
Any help wil be appreciated.
Thanks.
One of the more common setups would be having it all like this:
Filestructure:
/docroot
- /assets
+ /css
+ /js
+ /img
+ application
+ system
* .htaccess
* index.php
.htaccess (v1):
RewriteEngine on
RewriteCond $1 !^(index\.php|images|assets|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
or the more flexible way:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
and now in your markup you gotta load:
<link rel="stylesheet" href="/assets/css/whatever.css"></link>
<script src="/assets/js/bla.js"></script>
<img src="/assets/img/logo.png" alt="Nice Logo">
As for files not being accessible within the application folder, that's due to a .htaccess file in that folder denying all access in general. To prevent unintended file exposal.
And if you want to access files directly in the docroot, you would have to change to the second .htaccess version

merging two folder with mod-rewrite in .htaccess

I'm currently developing a drupal based website but will have to keep a legacy system and many static pages/folders alive. It would be great if i could keep the old rubble in a separate folder than the new site. This would mean I've to merge both folders on the fly. I thought that this folder structure would be great.
/htdocs/legacy (symlink to old web root)
/htdocs/index.php
/htdocs/.htaccess
/htdocs/other drupal files and folders
/htdocs/...
This would mean that if i.e. mydomain.com/xyz.php is accessed the server should try to serve it in the following order.
if file or folder in /htdocs/ server this
if file or folder in /legacy/ serve this but do not rewrite the browsers location bar.
else rewrite pass it as querystring to the
I came up with the following rewrite rules. Which however don't work. I can either serve files in legacy or via drupal.
# 1. server from .htaccess folder
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ - [NC,L]
# 2. serve from legacy
RewriteCond /full-path-to-legacy-folder/%{REQUEST_URI} -f [OR]
RewriteCond /full-path-to-legacy-folder/%{REQUEST_URI} -d
RewriteRule ^(.*)$ /legacy/$1 [NC,L]
# 3. else
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Has anyone of you suggestions?
Many thanks!
Since you're just rewriting the URL, and there are other operations that need to be done with the file (like mod_php), try changing your [L] options to [PT] to allow regular processing to continue on the request.

Resources