How to install laravel in addon domain - laravel-9

I have a addon domain on cpanel, inside the addon domain I created a folder lsc containing my laravel installation, the problem is laravel the laravel folder is redirecting me to lsc/public and I cant seem to view other pages the error is:
404
Not Found
The resource requested could not be found on this server!
what can I do to solve this cpanel problem ?, I have already use:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Yet no solution.
Thanks.

Related

Cakephp 3 prefix routing not working in linux server after SSL added

CakePHP Version: 3.6
I created a project with 3 route prefixes: admin, vendor and customer.
On my local machine it is working fine, all the prefixes are working fine. I moved my project to a remote Linux server and it was working fine at first. Once I added an SSL certificate and I access my website like this:
https://subdomain.myproject.com/vendor
It does not work. The browser keeps loading, and after some time it shows This site can’t be reached took too long to respond.
If I add a trailing slash it is working fine:
https://subdomain.myproject.com/vendor/
Other than the vendor prefix, the other prefixes are working fine as expected. Is it because CakePHP has a vendor folder or is it because of a server redirection?
Please guide me, how do I redirect http to https? I have added something to .htaccess, but it is also showing a 'too many redirects' issue.
If you have mod_dir enabled in Apache, it should by default automatically redirect your requests to the same URL with a trailing slash. From the Apache documentation:
A "trailing slash" redirect is issued when the server receives a
request for a URL http://servername/foo/dirname where dirname is a
directory. Directories require a trailing slash, so mod_dir issues a
redirect to http://servername/foo/dirname/
It's likely you do have this enabled, but check.
is it because cakephp has vendor folder
The vendor directory should not be publicly accessible in CakePHP, and I wouldn't expect there to be any issue with having a vendor routing prefix.
how to redirect http to https
Your .htaccess should look something like this, to force an HTTPS redirect and ensure CakePHP functions correctly:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# SSL redirect
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Required for CakePHP
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>

Unable to access sub-domain using .htaccess in my Laravel5.8 site on cpanel shared hosting

I got a Laravel 5.8 site hosted on shared hosting. I want to access my subdomain using .htaccess file but I'm unable to figure out how to make it work.
My directory structure looks like this:
public_html/
cdn/ (subdomain directory)
index.php
public/ (assets and index.php file reside here)
css/
js/
images/
fonts/
index.php (loads laravel site)
.htaccess (responsible to load index.php from the public directory)
So, basically, right now, if I try to access cdn directory like this http://example.com/cdn, that takes me to http://example.com/public/cdn and if I try http://cdn.example.com, the browser gives me the error message that This site can’t be reached.
I tried this but it does not work.
RewriteEngine On
# Handling subdomain
RewriteCond %{HTTP_HOST} ^(www.)?cdn.example.com$
ReWriteRule ^(.*)$ cdn/$1 [L]
# Loads index.php located inside laravel's public directory
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
ReWriteRule ^(.*)$ public/$1 [L]
When I try to access, http://cdn.example.com, the browser gives me the error message that This site can’t be reached.
It supposed to load index.php file located inside cdn directory.
Please help me out.
Thanks in advance!

unable to load php from interface folder

I am new to Apache and recently my developer passed me the website with htaccess to host on Apache 2.4 running on CentOS 7, the website is running on the Windows laptop but not on the server with the same htaccess.
The webpage works like this, when user hits the url at http://www.example.com, and click on the links, it will load the rest of the files from a folder called interface.
The original htaccess as follow:
RewriteEngine On
#this is for specific users
RewriteBase /v1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ /v1/index.php?m=$1 [QSA,NC,L]
ErrorDocument 404 /v1/error.php?=error
However it only load the main page, and the rest will load as follow:
Not Found
The requested URL /example was not found on this server.
I have tried the recommendations on this page Generic htaccess redirect www to non-www
and this page .htaccess for cakephp
and this page Remove .php extension with .htaccess
however all of them not working as what we want.
Any way I can get it to work?

RewriteRule for a file in a parent directory

I've got a site set up on an apache server with the desktop site in /public_html and a mobile site /in public_html/mob
I'm trying to set up an .htaccess rewriterule to send users to an index.php file in /public_html if they visit the /mob folder. My current rewrite rule, in the mob subfolder is:
RewriteRule ^(/)?$ ../index.php
I can load up the same file in the mob subdirectory with:
RewriteRule ^(/)?$ index.php
However I can't seem to get the site to load the index.php file from the parent directory (public_html).
When attempting to load http://www.domain.com/mob in a browser I receive:
Bad Request
Your browser sent a request that this server could not understand.
This same rewriterule worked fine on our development server, but doesn't work in our live environment.
The .htaccess file from the /public_html/mob folder is as follows:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(/)?$ ../index.php [L,QSA]
When index.php is reached a mobile device detect script decides whether to load the content from the desktop or mobile site.
Check DOCUMENT_ROOT of your m.domain.com.
If DOCUMENT_ROOT for your m.domain.com is /public_html/mob then you cannot load /public_html/index.php without doing a full redirect (or proxy) to http://domain.com/index.php
Just to clarify any web site cannot access files above its DOCUMENT_ROOT folder level.
If your rule's target starts with a /, that makes it an absolute URI starting from the document root, which I assume would be the public_html folder:
RewriteRule ^(/)?$ /index.php

Why is my .htaccess file redirecting to full server path instead of relative path?

I've never had a problem with cakePHP before, but something's odd about this server and is causing the redirects in the .htaccess files to behave oddly.
CakePHP uses mod_rewrite in .htaccess files to redirect requests to its own webroot folder. The problem is that the redirects are listing the wrong path and causing a 404 error. My CakePHP application, which is stored in the listings directory, has a .htaccess file as follows:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [R=301,L]
RewriteRule (.*) app/webroot/$1 [R=301,L]
</IfModule>
(*note that the R=301 causes an external redirect so we can see what is going on from our end. It should really omit this flag and do the redirect internally, transparent to end-users)
This is supposed to redirect any request from http://hostname.com/~username/listings/ to http://hostname.com/~username/listings/app/webroot/
However, rather than simply adding “app/webroot/” to the end as it is supposed to, it is adding the full server path ( /home/username/public_html/listings/app/webroot/ ) resulting in the final URL http://hostname.com/home/username/public_html/listings/app/webroot/ which is obviously incorrect and triggers a 404 error.
The hosting is on a shared hosting account, so that limits what I can do with the settings. I've never seen this happen before, and I'm thinking it's something wrong from the hosting side of things, but if anyone has some helpful suggestions then I can put them to the hosting company as well.
The solution to your question can be found towards the bottom of this page in the cakephp book:
For many hosting services (GoDaddy, 1and1), your web server is actually being served from a user directory that already uses mod_rewrite. If you are installing CakePHP into a user directory (http://example.com/~username/cakephp/), or any other URL structure that already utilizes mod_rewrite, you'll need to add RewriteBase statements to the .htaccess files CakePHP uses (/.htaccess, /app/.htaccess, /app/webroot/.htaccess).
I've deployed CakePHP from my profile's public_html folder as well. I had to change 3 the same .htaccess files mentioned above. Just add RewriteBase /~username/ to the .htaccess files just after RewriteEngine on!
Try removing .htaccess from main file... It worked for me
It was quite simple (using uolhost shared host):
Edit both .htaccess files:
/webroot/.htaccess
/.htaccess
Add the following line:
RewriteBase /
Here is the whole /webroot/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]