How to Remove index.php from urls

Discuss Search Engine Optimization in relation to Joomla! 2.5. This forum will also have discussions on SEF/SEO Joomla! 2.5 extensions.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
rehan3690
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Wed Apr 20, 2011 11:29 am

How to Remove index.php from urls

Post by rehan3690 » Wed Apr 20, 2011 12:44 pm

Hello friends

I am using Joomla 1.6(JA Methys 1.6 from joomlart)

Problem is every link has index.php like http://www.mysite.com/index.php/contact

http://www.mysite.com/index.php/about-us

how do i remove these .../index.php/.... from my urls



My SEO setting under Golbal Configuration are

==================================
Search Engine Friendly URLs Yes

Use Apache mod_rewrite Yes

Adds Suffix to URL No

Unicode Aliases No

Include Site Name in Page Titles No
==================================

I have changed htaccess.txt to .htaccess

I have tried every thing but unable to remove index.php in urls

Please help me

My apologies if this exists eslewhere

Thanks in advance

hanjimail
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 221
Joined: Sat May 31, 2008 12:15 am
Location: Yokohama, Japan
Contact:

Re: How to Remove index.php from urls

Post by hanjimail » Fri Apr 29, 2011 4:54 am

Hi. there!

Go to global configuration page.
Set Yes to URL rewriting.

That will remove index.php.

But, you have done this already. Its problem may be in .htaccess
or your server set-up.

Have you checked Joomla 1.6 required server environments?

PHP 5.2+
MySQL 5.0.4+
Apache 2.x+
Norito H.Yoshida, Yokohama, Japan
[email protected]
http://goyat.biz/

g1smd
Joomla! Guru
Joomla! Guru
Posts: 951
Joined: Mon Feb 21, 2011 4:02 pm
Location: UK

Re: How to Remove index.php from urls

Post by g1smd » Fri Apr 29, 2011 8:17 am

Once you have it working, you will need to add a redirect to your .htaccess file such that if URLs with index.php continue to be requested by users following old links in SERPs and in bookmarks they are redirected to the new URL without it.

Code: Select all

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.example.com/$1$2 [R=301,L]
I urge you to use the new .htaccess file that comes with Joomla 1.5.23 onwards and Joomla 1.6.2 onwards. Look for the file called htaccess.txt in the installer package. It contains a note showing exactly where the redirects should go (in addition to a number of other changes). Add your new redirect code in the file at the point it says "redirects go here", or similar.

You might also want to add this code too:

Code: Select all

########## Begin - 301 Redirect
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*(index|home)\.html?\ HTTP/
RewriteRule ^(([^/]+/)*)(index|home)\.html?$ http://www.example.com/$1 [R=301,L]
#
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.example.com/$1 [R=301,L]
#
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
########## End - 301 Redirect
Online since 1995.

sitehost
Joomla! Apprentice
Joomla! Apprentice
Posts: 33
Joined: Sun Feb 24, 2008 5:22 am

Re: How to Remove index.php from urls

Post by sitehost » Tue May 31, 2011 7:03 am

Are you using a Windows server?? if so you must have Mod rewrite.. but the server wont control what joomla renders...

Make sure your web.config.txt is renamed to web.config if your on a IIS server or that your htaccess.txt is .htaccess

And then Change your configuration settings to normal and then save, and retry your SEO Settings

Search Engine Friendly URLs are ON
Use URL rewriting is ON


let me know when you get it working.. if its doesnt let me know and ill take a look.

Bret

g1smd
Joomla! Guru
Joomla! Guru
Posts: 951
Joined: Mon Feb 21, 2011 4:02 pm
Location: UK

Re: How to Remove index.php from urls

Post by g1smd » Tue May 31, 2011 7:49 am

To clear up the confusing post above.

Use .htaccess if your server uses Apache.

Use web.config if your server uses IIS.
Online since 1995.

RealJames
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Fri Jun 03, 2011 11:03 am
Location: 神戸 三宮
Contact:

Re: How to Remove index.php from urls

Post by RealJames » Fri Jun 03, 2011 11:27 am

I realize this is late, but for anyone finding this thread in google, like I just did, I found a real simple way to solve the OP's problem!

put this in your .htaccess file

Code: Select all

RedirectMatch 301 ^/index.php/(.*)$ http://www.domain.com/$1
don't forget to change www.domain.com to your own domain!
www.realizeenglish.com - The Joomla site I manage :)

g1smd
Joomla! Guru
Joomla! Guru
Posts: 951
Joined: Mon Feb 21, 2011 4:02 pm
Location: UK

Re: How to Remove index.php from urls

Post by g1smd » Fri Jun 03, 2011 9:17 pm

RealJames wrote:Put this in your .htaccess file

Code: Select all

RedirectMatch 301 ^/index.php/(.*)$ http://www.domain.com/$1
don't forget to change http://www.domain.com to your own domain!
For many reasons you should not use RedirectMatch in the same .htaccess file as any RewriteRule directives. This code should be used:

Code: Select all

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.example.com/$1$2 [R=301,L]
Online since 1995.

g1smd
Joomla! Guru
Joomla! Guru
Posts: 951
Joined: Mon Feb 21, 2011 4:02 pm
Location: UK

Re: How to Remove index.php from urls

Post by g1smd » Mon Jun 13, 2011 7:27 pm

The canonical URL for the site root is http://www.example.com/ with a trailing slash and without index filename.
Online since 1995.

busybee2345
Joomla! Apprentice
Joomla! Apprentice
Posts: 19
Joined: Mon May 30, 2011 7:23 pm

Re: How to Remove index.php from urls

Post by busybee2345 » Sun Jun 19, 2011 4:04 pm

Hi

I also have the same problem removing the index.php from URLs. The use SEO-friendly URL and URL re-write options are enabled on joomla global configuration.

Apache version 2.2.16
PHP version 5.2.14
MySQL version 5.0.91-community
Joomla 1.6.3 mod_rewrite enabled by hosting company so we can access our own .htaccess files.

.htaccess file is ammended with the base URL
RewriteBase /~username/subdirectory

I have done this because the joomla installation is in a subdirectory. When I click a link to load a page the URL is re-written without the index.php/ but the page is not loaded and an error message informing of website maintenance appears instead. If I change the subdirectory path in .htaccess to anything else I get internal server error500 if I try to access any page.

Please help!

g1smd
Joomla! Guru
Joomla! Guru
Posts: 951
Joined: Mon Feb 21, 2011 4:02 pm
Location: UK

Re: How to Remove index.php from urls

Post by g1smd » Sun Jun 19, 2011 11:59 pm

When I click a link to load a page the URL is re-written without the index.php/
To be absolutely clear, do you see URLs without index.php in the browser status bar when you mouseover the on-page link without clicking it?

URL rewriting starts by publishing the right URL in the link on the page. It is too late to change the URL after the link is clicked.

Is the .htaccess file located at example.com/.htaccess or at example.com/folder/.htaccess here?
Online since 1995.

busybee2345
Joomla! Apprentice
Joomla! Apprentice
Posts: 19
Joined: Mon May 30, 2011 7:23 pm

Re: How to Remove index.php from urls

Post by busybee2345 » Mon Jun 20, 2011 12:57 pm

Hi, great to get your reply

URL

From the homepage when I click on a menu link to a sublevel page the re-written URL is shown correctly in the status bar of the browser e.g.

mysite.com/contact

However the page is not loaded, unless I go in and alter the URL to include /index.php/ when it works just fine.

.HTACCESS

.htaccess file I am ammending is located in the subfolder of the joomla installation - i.e. in

subfolder.myhostingdomain.com

where mysite.com is my domain name that maps to the subfolder above.

Hope that's a bit clearer!

g1smd
Joomla! Guru
Joomla! Guru
Posts: 951
Joined: Mon Feb 21, 2011 4:02 pm
Location: UK

Re: How to Remove index.php from urls

Post by g1smd » Mon Jun 20, 2011 1:26 pm

From the homepage when I click on a menu link to a sub-level page the re-written URL is shown correctly in the status bar of the browser.
That wasn't the question. The question is:
To be absolutely clear, do you see URLs without index.php in the browser status bar (that's the one at the bottom of the window) when you mouseover the on-page link without clicking it?
Online since 1995.

busybee2345
Joomla! Apprentice
Joomla! Apprentice
Posts: 19
Joined: Mon May 30, 2011 7:23 pm

Re: How to Remove index.php from urls

Post by busybee2345 » Tue Jun 21, 2011 5:43 pm

g1smd wrote:
From the homepage when I click on a menu link to a sub-level page the re-written URL is shown correctly in the status bar of the browser.
That wasn't the question. The question is:
To be absolutely clear, do you see URLs without index.php in the browser status bar (that's the one at the bottom of the window) when you mouseover the on-page link without clicking it?
Yes it shows correctly if you mouse over or click. But the page does not load.

g1smd
Joomla! Guru
Joomla! Guru
Posts: 951
Joined: Mon Feb 21, 2011 4:02 pm
Location: UK

Re: How to Remove index.php from urls

Post by g1smd » Wed Jun 22, 2011 6:15 am

The .htaccess file is not being read because it is in the wrong folder, or the RewriteBase value in the .htaccess file is incorrect.

Alternatively, the $livesite variable (in configuration.php) has the wrong value. It may even be a combination of those things.
Online since 1995.

User avatar
vseprav
Joomla! Apprentice
Joomla! Apprentice
Posts: 35
Joined: Mon Jun 20, 2011 2:23 pm
Location: Ukraine, Lviv
Contact:

Re: How to Remove index.php from urls

Post by vseprav » Wed Jun 22, 2011 1:24 pm

just need to activate mod_rewrite in .htaccess file

busybee2345
Joomla! Apprentice
Joomla! Apprentice
Posts: 19
Joined: Mon May 30, 2011 7:23 pm

Re: How to Remove index.php from urls

Post by busybee2345 » Fri Jun 24, 2011 10:17 pm

Thanks for your replies.

What should the 'livesite' variable be? The domain name people use to access the site or the physical location?

With the .htaccess file Base rewrite, if I change the path to anything other than the physical location the error is 'Internal Server Error' rather than the better error message I wrote for when a page can not be loaded. So I think it is the correct path? The URL is re-written but the page can not be loaded (apart from the homepage of course).

busybee2345
Joomla! Apprentice
Joomla! Apprentice
Posts: 19
Joined: Mon May 30, 2011 7:23 pm

Re: How to Remove index.php from urls

Post by busybee2345 » Fri Jun 24, 2011 10:53 pm

Update: well I've managed to find a solution - I basically just commented out the base rewrite rule and tried it with the .htaccess and it worked! Didn't need base rewrite or livesite after all.

Thanks everyone :-)

jawaune
Joomla! Apprentice
Joomla! Apprentice
Posts: 24
Joined: Sat Jun 18, 2011 11:00 am

Re: How to Remove index.php from urls

Post by jawaune » Wed Jun 29, 2011 11:21 am

Guys I am a little confused about renaming the htaccess.txt file. All files have extentions. Am I going to be renaming it to .htaccess without the .txt extension or is it going to be .htaccess.txt. I already tried chanting it to .htaccess without the .txt extension then changing my mod rewrite from no to yes and it didn't work. I experienced the same problem as the guy above. my home page would show but my other pages wouldn't. So is it supposed to be .htaccess.txt or just .htaccess? Because if it's just .htaccess without any extension, that sounds a little wierd to me.

g1smd
Joomla! Guru
Joomla! Guru
Posts: 951
Joined: Mon Feb 21, 2011 4:02 pm
Location: UK

Re: How to Remove index.php from urls

Post by g1smd » Thu Jun 30, 2011 7:18 pm

Filenames beginning with a period are system files. The name you need is exactly ".htaccess".

The file is distributed as "htaccess.txt" to make it easier to open in a standard text editor.
Online since 1995.

rehan3690
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Wed Apr 20, 2011 11:29 am

Re: How to Remove index.php from urls

Post by rehan3690 » Sat Jul 23, 2011 6:58 am

thnx to every one my problem got fixed

i enabled rewrite_module in apache modules

edited the code in .htaccess

thk u very much

g1smd
Joomla! Guru
Joomla! Guru
Posts: 951
Joined: Mon Feb 21, 2011 4:02 pm
Location: UK

Re: How to Remove index.php from urls

Post by g1smd » Mon Jul 25, 2011 9:11 pm

If Google has already indexed URLs with /index.php/ in them, you need a redirect to tell them that they need to de-index those URLs and index the new ones.

However, never mix RedirectMatch and RewriteRule directives in the same site. Use RewriteRule for all of your rules.

Code: Select all

RewriteRule ^index\.php/(.+)$ http://www.example.com/$1 [R=301,L]
Placement of this rule with respect to other rules (i.e. rule ordring) is very important.
Online since 1995.

idemodalje
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Wed Feb 17, 2010 8:48 am

Re: How to Remove index.php from urls

Post by idemodalje » Fri Oct 21, 2011 8:46 am

Hi guys,

I really hate this /index.php/

I set:
Search Engine Friendly URLs ON
Use URL rewriting ON

I changed htaccess.txt to .htaccess and I get correct url in browsers but also 404 page.

Please help :(

riprod
Joomla! Apprentice
Joomla! Apprentice
Posts: 34
Joined: Sun May 23, 2010 11:25 pm

Re: How to Remove index.php from urls

Post by riprod » Sun Oct 30, 2011 11:53 pm

Simple solution is add this to the .htaccess file

RewriteBase /.

Don't forget the . after the /
worked for me on Rackspace cloud

idemodalje
Joomla! Apprentice
Joomla! Apprentice
Posts: 14
Joined: Wed Feb 17, 2010 8:48 am

Re: How to Remove index.php from urls

Post by idemodalje » Wed Nov 02, 2011 9:49 am

Sorry guys, I made a mistake. ;)

It works great, with this to steps:

1) edit htaccess.txt to .htaccess
2) turn on seo in Joomla backend

thanks!

g1smd
Joomla! Guru
Joomla! Guru
Posts: 951
Joined: Mon Feb 21, 2011 4:02 pm
Location: UK

Re: How to Remove index.php from urls

Post by g1smd » Sat Nov 12, 2011 1:26 am

3) Set up a redirect so that requests for the old URL are redirected to the new URL. This forces searchengines to update the listings for your site, and retains the traffic to your site while the old URLs are still indexed and ranking.
Online since 1995.

Shai
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Mon Jan 16, 2012 2:48 pm

Re: How to Remove index.php from urls

Post by Shai » Mon Jan 16, 2012 2:51 pm

Hi everyone,

I'm still stumped by this and cannot remove it from our site, I've tried enabling SEO and apache rewrite,. I've even renamed the htaccess file and still no joy.

I've tried to redirect as well and still no joy, it keeps coming up with a 404 error.

Does anyone have any idea at all what it could be?

Thanks

velf
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Tue Jan 17, 2012 6:21 am
Contact:

Re: How to Remove index.php from urls

Post by velf » Tue Jan 17, 2012 6:31 am

g1smd wrote:Once you have it working, you will need to add a redirect to your .htaccess file such that if URLs with index.php continue to be requested by users following old links in SERPs and in bookmarks they are redirected to the new URL without it.

Code: Select all

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.example.com/$1$2 [R=301,L]
I urge you to use the new .htaccess file that comes with Joomla 1.5.23 onwards and Joomla 1.6.2 onwards. Look for the file called htaccess.txt in the installer package. It contains a note showing exactly where the redirects should go (in addition to a number of other changes). Add your new redirect code in the file at the point it says "redirects go here", or similar.

You might also want to add this code too:

Code: Select all

########## Begin - 301 Redirect
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*(index|home)\.html?\ HTTP/
RewriteRule ^(([^/]+/)*)(index|home)\.html?$ http://www.example.com/$1 [R=301,L]
#
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.example.com/$1 [R=301,L]
#
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
########## End - 301 Redirect
thanks. it work

adamlisit
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Mon Jan 23, 2012 12:58 pm

Re: How to Remove index.php from urls

Post by adamlisit » Mon Jan 23, 2012 1:05 pm

Took me out happy to read this comment. You are really blow job, things are happen in the world elegant nice post. Thanks for sharing the knowledge.

ellare
Joomla! Apprentice
Joomla! Apprentice
Posts: 42
Joined: Sat Feb 24, 2007 11:27 pm

Re: How to Remove index.php from urls

Post by ellare » Wed Jan 25, 2012 7:45 am

so in my case....

in my .htaccess file i have 1000+ rewriteRules for SEO/SERP because a site has been redesigned and moved to new server...

well... now here's what's happening.

{{Joomla 1.7 site}}

with URL Rewriting on - the site does not work. None of the navigation main menu links work.

with URL Rewriting OFF - site works great but has ugly index.php in all URLs

this is an example of the 1000+ rewrite rules I have in my .htaccess

RewriteCond %{QUERY_STRING} ^option=com_content&view=article&id=107&Itemid=193
RewriteRule ^index\.php$ http://www.thesitenamehere.org? [R=301,L]

with URL Rewriting on - mousing over link shows the correct URL structure - like http://www.thesitenamehere.org/news-events

but clicking on the nav menu link does nothing

config file shows live_site at http://www.thesitenamehere.org

mod_rewrite is on and enabled because it was all working beautifully before I did the 1000+ rewrites.

I think my error is in my rewrites / .htaccess file some how.

adding these bits to .htaccess made NO urls work - whether or not URL Rewriting was on or off - nothing worked

########## Begin - 301 Redirect
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*(index|home)\.html?\ HTTP/
RewriteRule ^(([^/]+/)*)(index|home)\.html?$ http://www.sitenamehere.org/$1 [R=301,L]
#
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.sitenamehere.org/$1 [R=301,L]
#
RewriteCond %{HTTP_HOST} !^(www\.sitenamehere\.org)?$
RewriteRule (.*) http://www.sitenamehere.org/$1 [R=301,L]
#
########## End - 301 Redirect

what kind of Redirect/Rewrite .htaccess monster have I created here??!?!

thanks


************ UPDATE

I cleared my browser's cache and everything is now working correctly. With URL Rewriting on, redirects are working. SEF are good.

working fine in FF8 and IE8

swhiteIN
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Sat Feb 18, 2012 6:14 am

Re: How to Remove index.php from urls

Post by swhiteIN » Sat Feb 18, 2012 6:22 am

I have successfully removed the index.php from my URLs (I think) but I am having trouble with the re-directs I think - here is what happens:

When I insert the following suggested code in the designated area on the .htaccess file whenever I go to an old link it simply takes me to the homepage rather than to the "new" non-index.php version of the page:

Code:
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.example.com/$1$2 [R=301,L]

If I instead enter the following code - it no longer takes me to the homepage but seems to not be doing a redirect as index.php remains in the URL. Also both the index.php and "new" non-index.php pages get picked up in a sitemap search when using the following code:

Code:
########## Begin - 301 Redirect
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*(index|home)\.html?\ HTTP/
RewriteRule ^(([^/]+/)*)(index|home)\.html?$ http://www.example.com/$1 [R=301,L]
#
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.example.com/$1 [R=301,L]
#
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
########## End - 301 Redirect

Can someone point to what is wrong here and which code is preferred and why I might be getting these anomalies with each? I don't want to send Google on a wild goose chase - SEO is very important. Thanks!


Locked

Return to “Search Engine Optimization (Joomla! SEO) in Joomla! 2.5”