View Full Version : Get rid of /index.php/ in your Joomla! URLs

vô danh
29-12-2012, 11:24 AM
The Global Configuration of Joomla! allows you to turn on SEF URLs, but this is either with or without Apache mod_rewrite. Without mod_rewrite (which might be needed because IIS is favoured over Apache), all URLs include an /index.php/ segment. But when you switch to Apache mod_rewrite after a while, you might want to redirect all old URLs with /index.php/ to URLs without /index.php/. This tutorial shows you how to accomplish this.

Modifying the htaccess-files
The key lies within the usage of the htaccess-file, which should be named .htaccess (starting with a dot, and without file-extension). If mod_rewrite is enabled, the htaccess-file allows you to activate the so-called RewriteEngine. This is used to redirect SEF-links to the Joomla! application-file index.php, but it can also be used to redirect old URLs to new URLs. In these cases, all additions are made just after the RewriteEngine statement, so before the actual Joomla! SEF-section.

RewriteEngine On
Removing /index.php/
To remove the /index.php/ part from all URLs, add two lines after the RewriteEngine statement:

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/index\.php/
RewriteRule ^index.php/(.*) /$1 [R,L]
Removing the .html suffix
You can also add two lines to remove the .html suffix if it has been turned on before:

RewriteEngine On
RewriteCond %{REQUEST_URI} \.html$
RewriteRule (.*)\.html$ /$1 [R,L]
Adding the .html suffix
Instead of removing the .html suffix, you might also want to add it to all URLs. But this becomes a little bit more complicated, because we don't want to rewrite requests for images, CSS-stylesheets and JavaScript-files. Also, when the browser calls the root of the URL (/) we don't want it to become /.html. Therefor the RewriteRules are a little bit more complicated:

RewriteCond %{REQUEST_URI} !\.html$
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_FILENAME} !index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /$1.html [R,L]

04-03-2013, 10:14 AM
Cảm ơn bạn, mình đã có thể chuyển từ có index về ko index rồi, vấn đề này mình bị trùng lặp nội dung may vào thấy topic này.