Removing index.php from SEF URLs

So you set up your Joomla! site, made it live, and later realised that you'd forgotten to enable the HTAccess file for SEF URL's.

The end result being that all your URLs contain /index.php/ What to do?

You could just enable the HTAccess file, but all the old URL's will then return a 404. Not great if your site has already been indexed by search engines, even worse if others have linked to you too.

In fact, on newer sites, it might even be worse - the old link will still be valid, but there'll be a 'new' link too, so you'll end up with two URLs for the same content.

It's actually incredibly simple to resolve, and this documentation details the two steps you need to take to resolve it, without breaking the old URLs.

 

The first step is simple, we need to enable the HTAccess file (assuming you haven't already). In the root of your Joomla! site is a file called htaccess.txt, rename it to .htaccess

The second step is to add a mod_Rewrite rule to catch and redirect the old-style links.

Open .htaccess in a text editor and find the line "RewriteEngine On". Immediately below add the following (lines with a hash are comments, you can skip these if needed)

# Make sure the requested URL isn't a directory (unlikely to be)
RewriteCond %{REQUEST_FILENAME} !-d

# Use a regular expression to find URL's where index.php is followed by something.
RewriteRule ^index.php/(.*)$ /$1 [R=301,L]

Save the file!

Now if you visit http://yoursite/index.php/category/Blogs/aPost/ you should be redirected to http//yoursite/category/Blogs/aPost/.

Because you're sending a 301 (Permanently moved), the search engines should update their indexes as well, and users browsers will cache the redirect (so if they visit again whilst the redirect is in cache, they'll immediately request the new URL).

So, for example http://www.bentasker.co.uk/index.php/documentation/joomla/266-removing-index-php-from-sef-urls should redirect you back to the correct URL for this article

 
 Share