Tag Archives: .htaccess

Quick way to prevent your Zend Controller from handling a Folder Tips, Tricks and Tutorials 30 JUN 2014

If you have a folder which you need to access in the standard way without your Zend Controller handling it for you (maybe a direct file download outside of your Zend web application), the easiest and quickest way to do this is to simply create a .htaccess file inside the folder you want your Zend controller to ignore and populate it with:

RewriteEngine Off

Because .htaccess files work in a cascading manner, this will overwrite the Zend controller .htaccess file in the root folder, in essence turning off mod_rewrite and thus giving you full control over the folder in terms of Apache now serving it as how it normally would.

zend-zf-logoQuick and easy.

(There are of course loads of other ways to do this, like implementing something like “RewriteRule ^(admin|user)($|/) – [L]” – if you want to ignore folders admin or user – at the top of your main Zend .htaccess file in root, but I like the above as a particularly quick and easy way to simply ignore a specific directory!)

WordPress: .htaccess Permalinks not Working (Ubuntu) Tips, Tricks and Tutorials 27 MAY 2014

If your freshly installed WordPress site is throwing standard 404 errors (the Apache default look and feel 404 pages mind you) instead of showing your content when accessing via permalinks, then chances are pretty pretty high that either a) WordPress can’t write to your .htaccess file or b) the Apache rewrite (mod_rewrite) module isn’t installed.

To solve this you’ll need to have SSH access into your Ubuntu server. Once you have logged in, head over to your WordPress install directory and see if there is a .htaccess file there:

ls -a .htaccess

If it isn’t there then that means that WordPress was unable to automatically create it, probably because of file rights. To resolve this, create a .htaccess file:

 touch .htaccess

And populate it with the following WordPress default .htaccess content:

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

Next, give it appropriate file rights:

chmod 755 .htaccess

Finally, let us go make sure that the Apache mod_rewrite module is installed by running the following:

sudo a2enmod rewrite
sudo service apache2 restart

With the mod_rewrite now enabled under Apache, next is to ensure that the AllowOverride directive is set appropriately for your Apache vhost directory declaration – you can use either AllowOverride FileInfo or AllowOverride All to achieve this. For example, for the default website, edit /etc/apache2/sites-available/default to reflect:

<Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            # changed from None to FileInfo
            AllowOverride FileInfo
            Order allow,deny
            allow from all
    </Directory>

With both of these now in place, your permalink problem should be solved.

horizontal wordpress logo landscape

WordPress: Switch to a New Domain by Setting a Permanent Redirect 301 via .htaccess CodeUnit 30 JUL 2012

Deciding that I really don’t have the desire nor free time to support multiple websites across multiple domains, I’ve started the process of copying all the content over from my unwanted WordPress sites to my primary WordPress site (at http://www.craiglotter.co.za) and then removing the unwanted installations. (Note: The WordPress Export/Import tools found under Tools work pretty damn well.)

However, because my unwanted sites still carry some decent link juice, SEO and SERP scores, I don’t necessarily want to lose all of that search engine goodness, and so set about setting up permanent redirection (301 HTML header) notices using the .htaccess file in the old accounts.

What this does is tell any search spider or browser where the content now sits, as well as the fact that it is a permanent redirect, meaning that hopefully the search engines update their indexes accordingly. Anyway, that’s the plan, but nevertheless, at least if you click in via an old link, you will still get transported to the desired content, albeit on a new domain! :)

To achieve this, first open your .htaccess file which you will find in the root of your WordPress installation directory. Note that this is a hidden file so you’ll need to edit it either via an FTP client or some other interface which allows you to list hidden files.

Once opened, be sure to remove all the WordPress rewrite rules which can be located between the “# BEGIN WordPress” and “# END WordPress” tags. Next, populate the .htaccess file with the following text at the top of the file:

<IfModule mod_rewrite.c>
# Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ http://www.craiglotter.co.za/$1 [R=301,L]
</IfModule>

# BEGIN WordPress
# END WordPress

Save the file and then try to hit an old URL like “http://www.codeunit.co.za/2010/01/16/php-simple-try-catch-example/” and note your browser automatically heading off to “http://www.craiglotter.co.za/2010/01/16/php-simple-try-catch-example/”.

Nifty.