Tuesday, April 2, 2019

Joomla SEF URL Problems [SOLVED 404 Error]

Hello Everyone, 

Recently my team and I worked and delivered a small Joomla website. After the site went live, I turned ON the SEF URL from the backend. But the URLs was still non-search engine friendly. I started to troubleshoot, finally, it started to work. I decided to document the steps through which it worked for me and the following are the steps. My intent is to educate.

Please note,
  • These steps are for an Ubuntu machine running Apache2 and I am using Joomla  3.X
  • Application is hosted at folder /var/www/html/JoomlaApp/
  • Demo URL for my site will be http://siteurl.com/JoomlaApp/


Preliminary checks or requirements 



  1. MOD_REWRITE: Very first step is to make sure mod_rewrite is enabled. By use of phpinfo(); one can verify if it is enabled or not. If it does not then use the command
    sudo a2enmod rewrite and then restart the web server.


  2. Rename htaccess.txt: Joomla provides its users with a default htacess.txt file. In order to enable SEF URL's this file needs to be renamed to .htaccess


  3.  Apache Configurations: The apache configuration needs to change so that it allows URL rewrites. I made changes for both HTTP & HTTPS configuration that is port 80 & 443.
    1. /etc/apache2/sites-available/000-default.conf
      • <VirtualHost *:80>
      • ServerAdmin webmaster@localhost
      •         DocumentRoot /var/www/html
      •         <Directory "/var/www/html">
      •         AllowOverride All
      •         </Directory>
    2. /etc/apache2/sites-available/default-ssl.conf
      • <VirtualHost _default_:443>
      •          ServerAdmin webmaster@localhost
      •         DocumentRoot /var/www/html
      •         <Directory "/var/www/html">
      •         AllowOverride All
      •         </Directory>


  4. Joomla Admin Configuration change
    1. Log into Joomla Admin console
    2. Go to System > Global Configuration  
    3. Locate SEO Settings and set the Use URL Rewriting option to Yes










As per Joomla documentation, the above steps should enable the SEF URL for your website, if it doesn't work then follow are the troubleshooting steps.

  1. Apache Configuration: As a habit, I copied the AllowOverride All code directly from the net and pasted it on the Apache configuration file. Which was a mistake. Apache configuration is very particular about the double quotes. "".  Hence please type it, do not copy paste it.


  2.  I made the following changes to my .htaccess file.
    1. Uncommented       # RewriteBase /      to        RewriteBase /

    2. My Joomla application exists inside another directory, like /var/www/html/JoomlaApp/. So I made the following change on Rewite Base
      1. RewriteBase /JoomlaApp/

    3. Added following piece of code after RewriteEngine On
      • ## Mod_rewrite in use.

      • RewriteEngine On
      • RewriteCond %{HTTP_HOST} ^siteurl.com/JoomlaApp/ [NC]
      • RewriteRule ^(.*)$ http://siteurl.com/JoomlaApp/$1 [L,R=301]

    4. Finally added following line of code at the very end of the file.
      • RedirectMatch 301 ^/index.php/(.*)$ http://siteurl.com/JoomlaApp/$1


  3. Another change I made was to the configurations.php file. I initialized the Live site variable as following, I am not sure, how helpful this particular change was, but it is there in the mix.
    • var $live_site = 'http://siteurl.com/JoomlaApp'; 


With all the above changes, the URL SEF for Joomla started to work for me. Please feel free to ask me any questions.

Thanx
Anshumaan Bakshi