Kirby .htaccess on VPS

Hi everyone.

I am using Kirby on a VPS and I’m having some trouble with Kirby’s htaccess file, in particular the rewrite rules.

My folder structure is like this:

|-/var
|-|-/www
|-|-|-/domain.com
|-|-|-|-.htaccess
|-|-|-|-index.php
|-|-|-|-/kirby
|-|-|-|-other (kirby) stuff

The error that I get is a 403 error. See for yourself: http://cool-house.nl/

My Kirby rewrite rules are as they were—as in: I haven’t changed them. Should I be running it in a subfolder? Or do I need to put an .htaccess in /var/www?

Thanks in advance!

No, the .htacces should be where it is. Have you made sure that overwriting server settings by .htaccess is allowed on your VPS? Alternatively, you could add those rules in your server config file.

Hi Texnixe, thanks for the reply!

I have indeed made sure that overwriting server settings by .htaccess is allowed (I followed a tutorial and when I restarted apache, I got the 403 error, which to me would indicate that .htaccess wasn’t doing anything before, and now it is).

Do you have any tutorials or guides or anything on how I should add those rules in my server config file?

edit: by the way, I tried setting the rewritebase to /, but that gives the same results.

I can’t give you any links, but maybe this example apache config file helps:

<VirtualHost ${VHOST_IP}:80>
 ServerName xxx.xxx.xxx
 ServerAdmin webmaster@xx.xx
 ServerSignature Email

 Use CustomerLogConfig 00000002 xxx.xxx xxx

 DocumentRoot "/srv/customers/00000002/vhosts/xxx/xxx/htdocs"

 <Directory "/srv/customers/00000002/vhosts/xxxx.xxx/xxx/htdocs">
  Options FollowSymLinks
  AllowOverride None
  Require all granted
  <IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteBase /
   RewriteRule ^content/(.*)\.(txt|md|mdown)$ error [R=301,L]
   RewriteRule ^site/(.*) error [R=301,L]
   RewriteRule ^kirby/(.*) error [R=301,L]
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^panel/(.*) panel/index.php [L]
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*) index.php [L]
  </IfModule>

  php_flag short_open_tag on

  <IfModule mod_headers.c>
   Header set X-Robots-Tag "noindex, nofollow, noarchive"

   <FilesMatch "\.(doc|pdf|png|jpe?g|gif)$">
    Header set X-Robots-Tag "noindex, noarchive, nosnippet"
   </FilesMatch>

  </IfModule>

 </Directory>

</VirtualHost>

Thanks!

So in my case, for directory, I would put “/var/www/cool-house.nl” ?

According to https://httpd.apache.org/docs/2.4/howto/htaccess.html this is even the preferred way of doing it, so that’s great.

[Edit] Sorry, I misread your post, yes, I think that should be the directory.

Hey,

Sorry to bring up this topic again I think I have a similar problem but I’m unable to solve it.

My folder structure is exactly the same as flobin. I’ve tried to setup the .htcaccess RewriteBase unsuccessfully. I can see the index page but when I try to enter a directory I keep getting the Not Found error.

May it be a apache problem like it seams to be for flobin? I couldn’t find the config file where I should modify the directory as texnixe proposes.

Thanks in advance for your help!

I had a similar problem when setting up on my VPS (Ubuntu 14.04 64-bit). Apache rewrite wasn’t working despite mod_rewrite being active and turned on via the .htaccess file. However, the .htacces file was being ingnored. I was getting 404s whenever the URL wouldn’t correspond to an actual file.

I found out that my problem was my default Apache Virtual Hosts file located at /etc/apache2/sites-available/000-default.conf. It read:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

	ErrorDocument 404 /index.html

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Turns out, this config file wasn’t allowing .htaccess to override default/server wide Apache settings, like mod_rewrite being off by default. I ended up adding the appropriate directives to allow .htaccess to override the settings. This is what my default vhost conf ended up looking like.

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
        <Directory "/var/www/html">
            AllowOverride All
            Require all granted
        </Directory>
	ErrorDocument 404 /index.html

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

This fixed my problem. I don’t know if this is your case as well, but it wouldn’t hurt to check. Hope it helps! Depending on your OS and web stack, the location of these files might vary.

This depends on your server setup, but you can do a simple test to check if the .htaccess file is read at all: just put some nonsense characters at the top of the file and if you get an error message, the file is called, if nothing happens, the file is ignored.

If you are on a VPS, you can put the contents of the .htaccess directly into your httpd.conf file, no need to use the .htaccess.

Good morning,

Thank you both for your answers.

I’ve tried the nonsense thing and as expected, the .htaccess is been ignored.

When I got into the default.conf file I saw that all the AllowOverride where at None and I changed that to all but it does still not work. There is some other server configuration that may be overriding the default configuration file? Maybe something outside my VB?

The only thing I didn’t try is the httpd.conf because I couldn’t find it.

I really appreciate your help.

This is an example Virtual Host setup which contains the Rewrite Rules instead of using the .htaccess, so all you would need to do is put that into your virtual host configuration for your domain, whatever that is called.

<VirtualHost ${APACHE_IP}:80>
 ServerName www.mydomain.com
 Use CustomerLogConfig 0000000x mydomain.com www
</VirtualHost>

<VirtualHost ${APACHE_IP}:443>
 ServerName www.mydomain.com
 ServerAdmin webmaster@mydomain.com
 ServerSignature Email

 Use CustomerLogConfig 0000000x mydomain.com www
 Include /etc/apache2/ssl_mydomain.com.conf

 Use Expires
 Use Deflate

 DocumentRoot "/srv/customers/0000000x/vhosts/mydomain.com/www/htdocs"

 <Directory "/srv/customers/0000000x/vhosts/mydomain.com/www/htdocs">
  Use DocRootStandard

#Include content of Kirby .htaccess
 
<IfModule mod_rewrite.c>
# enable awesome urls. i.e.:
# http://yourdomain.com/about-us/team
RewriteEngine on
RewriteBase /
RewriteRule ^content/(.*)\.(txt|md|mdown)$ index.php [L]
RewriteRule ^site/(.*) index.php [L]
RewriteRule ^kirby/(.*) index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^panel/(.*) panel/index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php [L]
</IfModule>

  php_flag short_open_tag 1
 </Directory>
</VirtualHost>
1 Like

Another reason could be that mod_rewrite isn’t enabled. Please try removing the <IfModule> tags around the rewriting configuration. If Apache then throws an error when starting up, you need to enable mod_rewrite first.

Solved!

Thank you very much, the problem was the server config Rewrite Rules as texnixe explained.