Hy my apache2.4.6 is not reading htaccess files

My 000-default.conf file is

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www
    <Directory "/var/www">
   Order allow,deny
   Allow from all
   AllowOverride FileInfo
   # New directive needed in Apache 2.4.3: 
   Require all granted
</Directory
    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

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

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf

</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Oh and my htacess file in wordpress was working on an older version of apache so that is not the problem

Thanks for any help

Dani AI

Generated

Good catch by on the missing </Directory>. If WordPress permalinks still do not work, the two most common Apache 2.4 gotchas are: (1) per-directory rewrites require FollowSymLinks to be enabled, and (2) on Ubuntu 13.10+ some defaults moved into apache2.conf, which can silently disable .htaccess if AllowOverride is still None there. In Apache 2.4, mod_rewrite in .htaccess only runs when Options FollowSymLinks (or SymLinksIfOwnerMatch) is on. Otherwise Apache forbids RewriteRule and nothing is rewritten. See Apache’s mod_rewrite notes on per-directory rewrites. (httpd.apache.org)

On Ubuntu/Debian, check both your vhost and /etc/apache2/apache2.conf. If apache2.conf contains a Directory "/var/www/" block with AllowOverride None, .htaccess is ignored even if your vhost tries to allow it. Either change that block or add a more specific one for the blog directory. After saving, reload Apache. DigitalOcean’s migration guide explains this packaging change for Apache 2.4 on Ubuntu. Also note that in 2.4 the default is AllowOverride None, which means Apache does not even attempt to read .htaccess unless you explicitly permit it. (digitalocean.com)

Minimal, safe change: keep your current Directory "/var/www" block and add the symlink option.

Options +FollowSymLinks

Place that line inside the Directory block that applies to /var/www (or create a dedicated <Directory "/var/www/blog"> section) and reload Apache. This enables rewrite processing in .htaccess. (httpd.apache.org)

Quick checks that avoid guesswork:

  • Confirm the right vhost is serving the request: apachectl -S.
  • Verify Apache still looks for .htaccess (default AccessFileName is .htaccess): apachectl -t -D DUMP_RUN_CFG. (httpd.apache.org)
  • For a subdirectory install like /blog, keep the WordPress rewrite rules alongside blog/index.php (or configure root rules intentionally). WordPress documents the subdirectory setup and will write the correct rules if it can. (developer.wordpress.org)

Once FollowSymLinks is enabled and AllowOverride is set in the place Apache actually merges, WordPress rewrites should start working.

Recommended Answers

All 8 Replies

At line 19 close the tag </Directory>. Then reload Apache and it should work. Also consider to enable the ServerName at line 9.

Sorry it tokk me so long to reply.
Thank you for the reply but unfortunately the server is not rewriting anything.
I closed the </Directory> tag but it's not happening
Oh and i would like to use the localhost as my servername

Can anyone show me what's wrong?

No problem. Are you sure .htaccess is not read? Can you show his contents? Do you get any message in the error.log file?

There could be a misconfiguration, for example with the actual setting if there is an Options call, the .htaccess will generate an error.

Most of the times you can place in the config file the same code that you would write into an .htaccess file, it will execute faster. So if in your old installation there were other settings, then this can explain the errors you get now. Right now the easiest test you can perform is to change AllowOverride to All and reload Apache.

I didn't edit any settings in my old apache it worked out of the box I just enabled apache rewrite,I tried your suggestion no luck.
Thank you

My htaccess

# BEGIN WordPress
<IfModule mod_rewrite.c>

RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

# END WordPress

Thank you

No errors apache2 log

[Sat Nov 16 20:28:58.740796 2013] [mpm_prefork:notice] [pid 1451] AH00163: Apache/2.4.6 (Ubuntu) PHP/5.5.3-1ubuntu2 configured -- resuming normal operations
[Sat Nov 16 20:28:58.740913 2013] [core:notice] [pid 1451] AH00094: Command line: '/usr/sbin/apache2'

Afetr modifications

Thank you

Ok, I do not see anything wrong. Maybe mod_rewrite is not enabled? You can check by running:

apache2ctl -M

Or in case of a Windows box:

httpd -M

Or simply remove the IfModule statements and see if it generates an error.

sudo a2enmod rewritemod rewrite is 100% enabled I even reinstaled it
I will try to remove IfModule.
Thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.