Laravel Shared Hosting .htaccess - php

I am trying to deploy a Laravel project onto a share hosting, I've managed to get most of the hard work done but I cannot strip off the /public directory without a Forbidden issue.
The website works and shows same pages for these links
www.mywebsite.com/test/index.php
www.mywebsite.com/test/public/
But without the /index.php It returns ->
Forbidden
You don't have permission to access /test/ on this server.
Currently my .htaccess looks like the following.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ public/index.php [L]
</IfModule>
Any ideas?

this is the magic script i use (add to the .htaccess in public_html)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

Try this rule in test/.htaccess:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /test/
RewriteRule ^$ public/index.php [L]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ public/index.php [L]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
</IfModule>

This script is working for me.
<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>

Related

How to run an existing cake php project in my local using xampp server in windows

This is my webroot .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteBase http://localhost/myproject/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
This is project folder .htaccess file
<IfModule mod_rewrite.c>
#RewriteEngine on
#RewriteRule ^(\.well-known/.*)$ $1 [L]
#RewriteRule ^$ webroot/ [L]
#RewriteRule (.*) webroot/$1 [L]
</IfModule>
This file is in app folder .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
Can any one help me out with this?
Try with below htaccess codes
/var/www/app/webroot/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
/var/www/app/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
/var/www/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
There can be following reasons for 500 Internal Server Error in CakePHP application:
1) Your .htaccess files are not correct.
2) Permissions of folders are not correct. If CakePHP app is Group Writable i.e. 777 then webserver gives 500 error for safety.
3) You are missing Database Connection. Correct database configuration according to Webhost because most of times local and production server databases have different details.
4) Delete the content of your tmp folder. It is best practice that you must delete cache if you move your application from one place to another.
5) For testing purpose debug should be on like configure::write('debug',2);
6) If not succeeded check your Apache Error Log. If using Linux /var/log/apache2/error.log
Hope It Helps, Thanks!!

Error 500 MVC with subdomain

I have a PHP MVC frame work.
I created a subdomain but it gives the error 500.
My root .htaccess file is like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ all_users/ [L]
RewriteRule (.*) all_users/$1 [L]
It redirects to the "all_users" folder.
The "all_users" root .htaccess is like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
The subdomain folder is in root of site.
How should I change the .htaccess file(s) for subdomain
redirection. Thanks.
I found the answer.
This is the .htaccess file in root of site:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain.domain.com$ [NC]
RewriteRule (.*) / [L]
RewriteRule ^$ all_users/ [L]
RewriteRule (.*) all_users/$1 [L]
</IfModule>

Coordino - The requested URL /test/install/database-config was not found on this server

Please help me how to resolve this error, I can't install it
I changed “database_sample.php” to “database.php” in app/config folder,
app/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
app/webroot/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
Then edit my Apache virtual host configuration, and changing
AllowOverride None
to
AllowOverride All
I don't know what to do anymore, do you have any suggestions?
There should be three .htaccess files, not two. For example, if Coordino is located under /var/www/, they should be:
/var/www/.htaccess
/var/www/app/.htaccess
/var/www/app/webroot/.htaccess
You're probably missing the first one. Its contents should be:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

mod_rewrite setting for CakePHP (shared hosting two domains)

I am running into an infinite redirection loop when setting up CakePHP on a bluehost server.
I have set my .htaccess as follows,
Under /home/mysite/public_html/site2 (I have configured an add-on domain with site2 as its serving directory on BlueHost)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Under /home/mysite/public_html/site2/app as,
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
And finally under /home/mysite/public_html/site2/app/webroot as,
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
If I remove the two RewriteCond from the .htaccess under webroot the Cake controllers start working but I don't see any images or CSS. I am not sure where am I going wrong.
creat a htaccess in root same as
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^site2\.tld[NC]
RewriteRule ^$ site2/app/webroot/ [L]
RewriteCond %{HTTP_HOST} ^site2\.tld[NC]
RewriteRule (.*) site2/app/webroot/$1 [L]
</IfModule>`
and htacess in site2 folder must be
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]

.htaccess rewrite parent folder to sub folder

how can i redirect from server.ip/~bogo/api/* to server.ip/~bogo/api/public/*?
any help please
Here's htacces in api directory
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
my htacces in public directory
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>
but i got 404 error??
Ok i solved it here's my solution
api directory htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /~bogo/api/
RewriteCond %{REQUEST_URI} !/public/
RewriteRule (.*) public/$1
</IfModule>
public directory htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /~bogo/api/public/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>
Apache will go through .htaccess until no rules match anymore. The problem you are most likely facing, is that the new url is being matched by the regex of the same rule. You have created an infinite loop. You can fix this by making sure the rule doesn't match if the url already has 'public' in it:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !/public/
RewriteRule (.*) public/$1 [L]
</IfModule>

Categories