.htaccess File
Principle
In the root folder of your installation there should be a file called .htaccess
.
This file optimizes the way the Apache web server works with b2evolution. This file sort of auto-configures Apache. The settings in this file are notably required for using "clean URLs". See Collection Base URL Panel.
Note: There are also other .htaccess
files in sub-directories. Those have a different purpose. They typically prevent unauthorized access to certain files.
Note: .htacess
files only work if your webserver uses Apache. If you use NginX for example, you need to configure your webserver differently/manually.
Semi-automatic install
If you used the standard b2evolution installer, this file will probably be already set up properly. However, if there already was a .htaccess
file on your site, b2evolution does not overwrite it by default. In this case you need to edit or replace the file manually.
If in doubt, make sure your .htaccess
file has the same contents as the sample.htaccess
that ships with b2evolution.
Note: because the name of the .htaccess
file starts with a dot, it may be hidden in your cPanel file manager, in your FTP client software as well as on the Linux command line. You may need to enable display of hidden files in order to see the .htacess
file.
Typical .htaccess
Here is a good template to use for your .htaccess
file for b2evolution v6.7:
# Apache configuration for b2evolution's base folder
# Lines starting with # are comments.
# Updated 2016-01-25
# PHP / SECURITY:
<IfModule mod_php5.c>
# On some overly "secured" systems, the following may need to be added in each folder:
# AddHandler application/x-httpd-php5 .php
# The following will try to configure PHP in the way b2evolution would like it to be:
# However, these falgs will only work if the server configuration allows them...
# Increase memory limit
php_value memory_limit 384M
# Security settings
php_flag register_globals Off
php_flag allow_url_include Off
php_flag magic_quotes_gpc Off
# For uploading
php_value upload_max_filesize 32M
php_value post_max_size 40M
# You may increase the following if PHP is not able to increase it by itself when needed
# Otherwiwse it's better to keep the number low enough for general use
php_value max_execution_time 30
# You may want to turn the following to Off on production servers
# Please do this only if you know what you're doing and will be able to retrieve potential errors from your error log
php_flag display_errors On
# The following is the same as 'E_ALL & ~ E_STRICT' (except those constants may not be available here)
php_value error_reporting 30719
</IfModule>
# DISABLE LISTING FILES ON SERVER:
# Don't show directory contents (not desirable, especially for media folders)
Options -Indexes
# Note: if you have access to the command line of your server, it would probably
# be even better to type this: a2dismod autoindex
# (This disables the directory listing module completely)
# DEFAULT DOCUMENT TO DISPLAY:
# In case no specific file is requested, we want to fall back to index.php
# In case some subdirectories are accessed, we want to display index.html
<IfModule mod_dir.c>
DirectoryIndex index.php index.html
</IfModule>
# CLEAN URLS:
# The following will ensure you can pass extra params after the filename on the URL
AcceptPathInfo On
# CATCH EVERYTHING INTO B2EVO: (even if no php file appears in the URL)
# The following will allow you to have a blog running right off the site root,
# using index.php as a stub but not showing it in the URLs.
# This will add support for URLs like: http://example.com/2006/08/29/post-title
<IfModule mod_rewrite.c>
RewriteEngine On
# This line may be needed or not.
# enabling this would prevent running in a subdir like /blog/index.php
# RewriteBase /
# Redirect to REST API controller:
RewriteRule ^api/v(\d+)/(.+)$ htsrv/rest.php?api_version=$1&api_request=$2 [QSA,L]
# Redirect any .htm .html or no-extension-file that's not an existing file or directory to index.php:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^[^.]+(\.(html|htm))?$ index.php [L]
</IfModule>
Troubleshooting
If you have your .htaccess
file in place but some things don't work, especially, for example, if the mod_rewrite
rules seem to be ineffective, try the following:
- Check that
mod_rewrite.c
also known as the "Rewrite Module" is enabled in your Apache - You can validate that by removing
<IfModule mod_rewrite.c>
and</IfModule>
from the.htaccess
file and see if this results in an error or not. - Check your apache server configuration or virtual host configuration for a directive like
AllowOverride None
and change it toAllowOverride All
(without that, the .htaccess
rules would be ignored)
For NginX, see this forum thread: http://forums.b2evolution.net/nginx-config