Misconfigured .htaccess file on bluehost

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

I followed the cookbook here:
https://book.cakephp.org/4/en/installation.html

.htaccess in webroot:

<IfModule mod_rewrite.c>
    RewriteEngine On
    #RewriteBase /path/to/app
	RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

.htaccess in the root directory:

#not sure if this belongs in this file
#don't know what the path to mod_rewrite.so is
#LoadModule rewrite_module libexec/apache2/mod_rewrite.so

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$    webroot/    [L]
   RewriteRule    (.*) webroot/$1    [L]
</IfModule>

<Directory />
    Options FollowSymLinks
    AllowOverride All
</Directory>

<Directory /home4/maureep0/public_html/mysitesfolder>
    Options FollowSymLinks
    AllowOverride All
    Order Allow,Deny
    Allow from all
</Directory>

I tried the online tester at https://htaccess.madewithlove.be/ but it mostly returned: “This line is not supported by our tool.”

Ok so, you don’t need that <Directory> stuff, that’s for a completely different file (httpd.conf) in case the original rewrites don’t take.

The .htaccess in root really only exists for your protection, in case you accidently publish that instead of your webroot folder. When you set your public folder (for what is seen when they go to the site) that is webroot which you “share”.

Try this in your root folder: -

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [L]
</IfModule>

which is just saying if somehow a browser got to this folder then throw them to the public one. Its poor security as they could manually type in full paths if they knew it was a CakePHP app and perhaps find something they shouldn’t.

.htaccess is eye-of-the-beholder (although correct me if I’m wrong) in that its relative to what the client browser sees - written from their perspective.

Again that stuff RewriteBase shouldn’t be needed - only if you got a funky setup. So your .htaccess in your webroot need only be: -

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^ index.php [L]
</IfModule>

Which is just a bit of routing protection for dead links.

If I haven’t got it right then you’ll need an expert :slight_smile:

for example here are my .htaccess files from project running on shared webspace at ionos:
in root directory:

<IfModule mod_rewrite.c>
RewriteEngine on

#the next 2 lines are only for forwarding to https
RewriteCond %{SERVER_Port} !=443
RewriteRule ^(.*)$ https://yourdomain.com/$1 [R=301,L]
# end of forwarding

RewriteBase /
RewriteRule ^(\.well-known/.*)$ $1 [L]
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>

in folder webroot :

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

I used dirk’s code and it worked. Thanks, dirk.

Thanks, Jawfin for providing so much info

Heh, no worries. I actually removed my https redirections in my post so as to not confuse, as there can be more work for that; getting a certificate etc. I also force redirect my website to https.

Glad you got it working :slight_smile: