I built international site and it adds language code to the end of the urls: www.site.com/index.php/en/ I enabled SEF urls and url rewriting in global configuration, I tried many .htaccess snippets to remove index.php but it keeps forwarding me to page not found, below is the snippet I used:

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/index\.php/
RewriteRule ^index.php/(.*) /$1 [R,L]

Please advice me the right way to remove index.php and keep the language code.


.htaccess code:

 <IfModule mod_rewrite.c>                                        
 RewriteEngine On                                                

 #Force www:                                                     
 RewriteEngine on                                                
 RewriteCond %{HTTP_HOST} ^ncci-server.com [NC]                  
 RewriteRule ^(.*)$ http://www.ncci-server.com/$1 [L,R=301,NC]   

 #REWRITE RULES                                                  

 RewriteBase /MainSite/                                          

RewriteCond %{REQUEST_URI} !^/index\.php                                              
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]  
RewriteCond %{REQUEST_FILENAME} !-f                                                   
RewriteCond %{REQUEST_FILENAME} !-d                                                   
RewriteRule .* index.php [L]                                                          
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]                       

#remove index.php                                                                     
### Redirect index.php to Root                                                        
RewriteCond %{THE_REQUEST} !^POST                                                     
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/                            
RewriteCond %{SERVER_PORT}>s ^(443>(s)|[0-9]+>s)$                                     
RewriteRule ^index\.php$ http%2://www.ncci-server.com/ [R=301,L]                      

#RULE JOOMLA! RULE 2                                                                  
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]                          
RewriteCond %{QUERY_STRING} (>|%3C)([^s]*s)+cript.*(&lt;|%3E) [OR]                    
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]                        
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})                            
    <Files ^(.*)$>                                                                            
    ErrorDocument 403 "Forbidden"                                                     
# STARTS WITH WEB                                                                                                                                       
    RewriteCond %{HTTP_USER_AGENT} ^web(zip|emaile|enhancer|fetch|go.?is|auto|bandit|clip|copier|master|reaper|sauger|site.?quester|whack) [NC,OR]      

# ANYWHERE IN UA -- GREEDY REGEX                                                                                                                        
    RewriteCond %{HTTP_USER_AGENT} ^.*(craftbot|download|extract|stripper|sucker|ninja|clshttp|webspider|leacher|collector|grabber|webpictures).*$ [NC] 

# ISSUE 403 / SERVE ERRORDOCUMENT                                                                                                                       
    RewriteRule . - [F,L]                                                                                                                               

########## Begin - Rewrite rules to block out some common exploits                                                                                      
## If you experience problems on your site block out the operations listed below                                                                        
## This attempts to block the most common type of exploit `attempts` to Joomla!                                                                         
# Block out any script trying to set a mosConfig value through the URL                                                                                  
    RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]                                                                                  
# Block out any script trying to base64_encode crap to send via URL                                                                                     
    RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]                                                                                              
# Block out any script that includes a <script> tag in URL                                                                                              
    RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]                                                                                      
# Block out any script trying to set a PHP GLOBALS variable via URL                                                                                     
    RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]                                                                                      
# Block out any script trying to modify a _REQUEST variable via URL                                                                                     
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})                                                                                              
# Send all blocked request to homepage with 403 Forbidden error!                                                                                        
    RewriteRule ^(.*)$ index.php [F,L]                                                                                                                  
########## End - Rewrite rules to block out some common exploits                                                                                        

########## Begin - Common hacking tools and bandwidth hoggers block                                                                                     
## By SigSiu.net and @nikosdion.                                                                                                                        
# This line also disables Akeeba Remote Control 2.5 and earlier                                                                                         
    SetEnvIf user-agent "Indy Library" stayout=1                                                                                                        
# WARNING: Disabling wget will also block the most common method for                                                                                    
# running CRON jobs. Remove if you have issues with CRON jobs.                                                                                          
    SetEnvIf user-agent "Wget" stayout=1
  • Does joomla resides in a directory called MainSite in the root folder? or it is in the root folder? – FFrewin Jun 9 '15 at 11:25
  • Also is this accurate: www.ncci-server.com ; or just a dummy domain for posting purposes here? – FFrewin Jun 9 '15 at 11:29
  • yes joomla site resides in MainSite folder, and I make appache virtual hosts and added an A record in the dns configurations – Ya Basha Jun 9 '15 at 11:29
  • it's an active domain I'm building my site at www.ncci-serve.com – Ya Basha Jun 9 '15 at 11:32
  • I would suggest to rename the current htaccess file and create a new one, containing only the content of the default htaccess.txt file. Then test with URL rewrite ON. If indeed the joomla installation is not in the root, you ill find it out, because you won't be able to access other pages, then uncomment the RewriteBase and add the path of the joomla install. For the rest rules: keep adding them one by one while testing. – FFrewin Jun 9 '15 at 11:37

Enable URL Rewriting

What you have to do, is to enable URL rewriting. It can be done in the backend:

Global Configuration -> Site -> Use URL Rewriting (set to yes)

or directly in the configuration.php file of the Joomla instance:

public $sef_rewrite = '1'; //1 = enabled, 0 = disabled;

Note: When enabling the URL rewriting, an .htaccess file should exist in the root of the Joomla site.

RewriteBase in htaccess:

If your site is not in the root folder, then you will also have to uncomment the RewriteBase rule in the .htaccess file and add the path to the folder where your site resides, eg.:

RewriteBase /myjoomlafolder

Redirect index.php to home page (htaccess):

Finally, if you are also want to remove the index.php from the home page, therefore to remove the duplicate urls for the homepage, something like this should do the trick:

### Redirect index.php to Root
RewriteCond %{THE_REQUEST} !^POST
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteCond %{SERVER_PORT}>s ^(443>(s)|[0-9]+>s)$
RewriteRule ^index\.php$ http%2://mysite.com/ [R=301,L]
  • I followed the above exactly but now it gives me: No data received – Ya Basha Jun 9 '15 at 11:13
  • Clear caches and refresh, try with other browsers as well with cleared caches, to see if your site plays ok, then if you did everything on the above, undo them and re-do them one by one. Actually for your initial question you only need to enable url rewrite in global config. – FFrewin Jun 9 '15 at 11:21
  • No I already enabled it and renamed htaccess.txt, I added the code for .htaccess so you can check – Ya Basha Jun 9 '15 at 11:22

It should not be necessary to modify/add your .htaccess rules in order to remove index.php from your url, it usually works out of the box if you enable URL Rewriting in the Joomla Configuration, and rename htaccess.txt to .htaccess.

Although you seem to have found a solution, I'd like to add a clarification on the use of RewriteBase in the .htaccess file:

RewriteBase /JoomlaSubFolder

This line should be un-commented and edited if you have installed Joomla in a subfolder on your server (in this case, ROOT/JoomlaSubFolder). However, this is relative to your URL, so it is only correct if you access your site using http://example.com/JoomlaSubFolder (or http://localhost/JoomlaSubFolder).

On the other hand, if you have installed Joomla in the same subfolder, but use a unique URL to access the site (e.g. http://joomla.example.com, http://example2.com, or http://www.ncci-server.com/), you should leave it as it is in the default .htaccess file:

# RewriteBase /


RewriteBase /

This is often the case when using addon domains on Apache servers, as these are located within a subfolder of the main domain, but has a different domain assigned.


I'm using apache virtual hosts so the right way to use url rewriting:

  • Enable Apache Mod_Rewrites (if not enabled): sudo a2enmod rewrite
  • Edit apache site config file: sudo nano /etc/apache2/sites-available/default

    <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
  • sudo service apache2 restart
  • Enable URL Rewriting (Joomla Configuration)
  • Rename htaccess.txt to .htaccess

Now URL Rewriting will work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.