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.
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 Feb 18, 2012 7:50 am

Use the Live HTTP Headers extension for Firefox to watch the headers in the HTTP transaction. It will likely give you a clue as to what is happening.
Online since 1995.

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 » Sun Feb 19, 2012 4:35 am

Thanks - I checked using the Firefox tool and its as I assumed. If the redirect box contains the following (regardless of whether the additional language you suggested is there or not) any page that previously had an "index.php" now redirects only to the homepage (using a 301) not to its new non-"index.php" 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.net/$1$2 [R=301,L]

The inclusion or exclusion of the additional language you have seems to make no difference. I will say that if I put no redirect at all in place - I still can get to the index.php pages if I type it in, they are just not the preferred link created by Joomla now. They are still in existence however.

lpcalhoun
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Wed Feb 15, 2012 7:20 pm

Re: How to Remove index.php from urls

Post by lpcalhoun » Sun Feb 19, 2012 7:33 pm

Hello, I'm having the same index.php issue as the others. I'm just goofing around trying to learn joomla on my personal website. The index.php thing is driving me crazy. I've read these posts several times and could use some help. Thanks in advance.

When I hover over a menu item, urls display without index.php, when menu item is clicked the page trys to open but displays Page not found. If you type in the index.php, the page opens.

http://www.calhounsplace.com
Site is hosted on fatcow-apache

I have search engine friendly URL set to yes
and use URL rewriting set to yes

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

configuration.php exerpt
public $live_site = 'http://www.calhounsplace.com';

mobi_SA
Joomla! Intern
Joomla! Intern
Posts: 53
Joined: Tue Aug 16, 2011 6:06 am

Re: How to Remove index.php from urls

Post by mobi_SA » Tue May 08, 2012 4:56 pm

Hello guys,

I have the same issue what the other people above..i want to remove index.php & i gor 404 error

i have inserted the code too in .htacess file but when i set URL rewriting -> Yes it shows me 404 error on the front end.

Second thing which is worst than this that when i disable that URL rewriting it shows me blank page in front end, though it was working before renaming the .htacess.txt file to .htacess

I have also tried after copied a new .htacess.txt file from joomla installation package but nothing change it is showing me a blank page

Kindly guide me how did you do i recover my site..& remove index.php

mobi_SA
Joomla! Intern
Joomla! Intern
Posts: 53
Joined: Tue Aug 16, 2011 6:06 am

Re: How to Remove index.php from urls

Post by mobi_SA » Tue May 08, 2012 5:17 pm

i have included "." in the beginning of htaccess, now it just show me blank page..now it does'not show me the 404 error.

But why is it doesnot showing me the article..

if i typed any thing wrong with url like "www.example.com/wrongpage" then it show me 404 error with the template what i have..but when i click on any menu item..it shows me a blank 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 » Tue May 08, 2012 9:07 pm

Use the Live HTTP Headers extension for Firefox to examine the returned server headers.
Online since 1995.

mobi_SA
Joomla! Intern
Joomla! Intern
Posts: 53
Joined: Tue Aug 16, 2011 6:06 am

Re: How to Remove index.php from urls

Post by mobi_SA » Wed May 09, 2012 1:58 pm

Thanks man its working..u know what is the mistak..i have place the wrong php code in template it shows me the blank page & i didnt place "." before htacess name..So when i correct both of these things..it start working..

Sir really thankful to you for your reply.:)

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 May 09, 2012 2:48 pm

An easy mistake to make. And completely fatal to the whole website.

Glad you got it fixed!
Online since 1995.

mobi_SA
Joomla! Intern
Joomla! Intern
Posts: 53
Joined: Tue Aug 16, 2011 6:06 am

Re: How to Remove index.php from urls

Post by mobi_SA » Wed May 09, 2012 2:57 pm

yeah true..it completely fatal for whole website...
Thanks for your respond:)

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 May 09, 2012 5:09 pm

Those are the best types of errors to have. They get your attention very quickly.

Errors that fester away in the background, eroding the site indexing and ranking are the worst type of errors. It may be months before you realise that anything is wrong and by then it may be too late.
Online since 1995.

wyfytangsh
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Thu Apr 19, 2012 9:28 am
Contact:

Re: How to Remove index.php from urls

Post by wyfytangsh » Thu May 10, 2012 6:24 am

velf wrote:
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
I am so happy !!!

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 May 12, 2012 11:11 am

Thanks for the feedback. This code has been thoroughly tested many times now. As long as you follow all the steps it should work as advertised.

It's good to know that code developed when Joomla 1.4 / 1.5 was standard, still works with the latest versions too.
Online since 1995.

IIphynixII
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Sat May 12, 2012 11:29 am
Contact:

Re: How to Remove index.php from urls

Post by IIphynixII » Sat May 12, 2012 11:40 am

Hallo Everyone

I did this stuff, and got it to work. So now my page show: www.domain.com for every page I have.
How do I make it go into www.domain.com/artical-name ?

Thanks in advance.

//IIphynixII

logicc
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Thu Jun 28, 2012 7:07 pm

Re: How to Remove index.php from urls

Post by logicc » Thu Jun 28, 2012 7:14 pm

Hi all,

I got this working using these rules

Code: Select all

# redirect non www to www
RewriteCond %{HTTP_HOST} ^domain.co.uk [NC]
RewriteRule ^(.*)$ http://www.domain.co.uk/$1 [L,R=301]

# Remove index.php from internal pages
RewriteCond %{THE_REQUEST} !^POST
RewriteCond %{SERVER_PORT}>s ^(443>(s)|[0-9]+>s)$
RewriteRule ^(([^/]+/)*)index\.php/(.*)$ http%2://www.domain.co.uk/$1$2 [R=301,L]

# force remove of index.php or index.html from home page 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*)index\.(php|html?)\ HTTP/
RewriteRule ^([^/]+/)*index\.(html?|php)$ http://www.domain.co.uk/$1 [R=301,L]
Works perfectly apart from one thing, it stops adminstrator area working, this seems to need to index.php to function. Anyone know how to prevent the rule being applied on admin? I think its a simple regex change....

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 28, 2012 9:36 pm

Your rules are in the wrong order.

There are syntax errors and logic errors.

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 %{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]
#
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
########## End - 301 Redirect
Online since 1995.

logicc
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Thu Jun 28, 2012 7:07 pm

Re: How to Remove index.php from urls

Post by logicc » Wed Jul 04, 2012 3:23 pm

g1smd wrote:Your rules are in the wrong order.

There are syntax errors and logic errors.

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 %{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]
#
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
########## End - 301 Redirect

Thanks for that, admin now works with the index.php removal in place. THe only thing left that is not 100% is this
http://www.domain.com/index.php/pagename ---> http://www.domain.com/pagename

Current any urls with index.php in the middle just redirect to http://www.domain.com

Any ideas?

(and thanks a lot as this issue was doing my head in somewhat!)

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 Jul 04, 2012 8:38 pm

Ruleset 3 should take care of that. No idea why it isn't doing so.
Online since 1995.

logicc
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Thu Jun 28, 2012 7:07 pm

Re: How to Remove index.php from urls

Post by logicc » Thu Jul 05, 2012 7:43 am

Yer its weird. What is the %2 is that to allow for https?

http%2://www.....

adineh
I've been banned!
Posts: 21
Joined: Sat Sep 17, 2011 4:05 pm

Re: How to Remove index.php from urls

Post by adineh » Fri Jul 06, 2012 8:38 am

hi friends
i use windows server its mean i must use it in web.config
but can you give me the code that i must put it in web.config

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 Jul 06, 2012 10:05 pm

Yes, the %2 takes care of https requests.
Online since 1995.

Adrian98
Joomla! Intern
Joomla! Intern
Posts: 54
Joined: Wed Feb 08, 2012 8:54 am
Contact:

Re: How to Remove index.php from urls

Post by Adrian98 » Tue Jul 10, 2012 8:58 am

Well, first of all make sure to check the server environment and then make sure you have activated the mod.rewrite in .htaccess file ! Or straight and simple way is to get the upgraded package of Joomla and copy the .htaccess file from the installer package to your current Joomla's .htaccess and activate the rewrite mod!
Please read the Forum rules regarding signatures: http://forum.joomla.org/viewtopic.php?t=65

logicc
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Thu Jun 28, 2012 7:07 pm

SOLVED : How to Remove index.php from urls

Post by logicc » Tue Jul 10, 2012 9:59 am

HI all,
Thanks to everyone for assistance here is the final working code which does everything i need and does not break admin.
########## Begin - Custom redirects
########## Actions : Redir any other domains or nonwww to www. Removes index.php from home and any internal pages

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

# Remove index.php from sub pages e.g. http://www.domain.com/index.php/about --> http://www.domain.com/about
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.domain.com/$1$3 [R=301,L]

RewriteCond %{HTTP_HOST} !^(www\.domain\.com)?$
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
#
########## End - 301 Redirect
########## End - Custom redirects
This works on Joomla 1.5 - 2.5 no problem. Ive tried the 2.5 default .htaccess and this doesnt do all of the above. Hope this helps someone else but its made an instant different to my seo.

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 Jul 11, 2012 1:00 am

Thanks for the report that the code continues to do what it is supposed to do and works on current versions of Joomla too.

You found a typo in the code posted earlier in this thread.

Your example shows that $2 should be $3. Good catch.
Online since 1995.

michaeldj
Joomla! Apprentice
Joomla! Apprentice
Posts: 31
Joined: Fri Jul 06, 2012 6:16 am
Location: IN
Contact:

Re: How to Remove index.php from urls

Post by michaeldj » Wed Jul 11, 2012 6:09 am

hey i would like to say that do parment redirecion... that will really help you to get all benefits...

suppose you have two address & you have give to me both address & you din't address me for where you can meet me so i would be confuse to where i have to reach.

you can do one thing that do parment redirection because of that you will get page rank value. suppose any body will lend on .index.php than you website will be redirect to home page...

thanks,

logicc
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Thu Jun 28, 2012 7:07 pm

Re: How to Remove index.php from urls

Post by logicc » Wed Jul 11, 2012 7:46 am

michaeldj wrote:hey i would like to say that do parment redirecion... that will really help you to get all benefits...

suppose you have two address & you have give to me both address & you din't address me for where you can meet me so i would be confuse to where i have to reach.

you can do one thing that do parment redirection because of that you will get page rank value. suppose any body will lend on .index.php than you website will be redirect to home page...

thanks,
Hi Michael,
I believe all the redirects are permanent (301). Also anyone landing on a page with index.php in url will be redirected to a single, non index.php variation of the url.
DAve

@g1smd - yer that one was a breakthrough when i spotted it!!

User avatar
seomatrix
Joomla! Apprentice
Joomla! Apprentice
Posts: 19
Joined: Fri Sep 09, 2011 4:55 pm
Location: Düsseldorf
Contact:

Re: How to Remove index.php from urls

Post by seomatrix » Wed Jul 11, 2012 4:17 pm

RewriteRule ^(.*)yourvariable(.*)$ http://www.example.com/$1yourvariable$2 [R=301,L]

This rule changes:
www.example.com/directory/yourfile.html to
www.example.com/yourfile.html

you can also try to set your variable simply with index.php (because its included in the filename)

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 Jul 11, 2012 9:09 pm

NEVER use (.*) at the beginning of a RegEx pattern.

The first (.*) is greedy and matches the entire input string. The parser then has to invoke thousands of "back off and retry" trial matches to "find" /directory/ before working forwards again.

The rule "changes" nothing. It merely redirects requests to a different URL.


There are three redirect HTTP status codes:
301 is "permanent". This is the most common.
302 and 307 are "temporary" and rarely needed.


I have no idea how that typo made it into the code here. It's repeated in a number of posts. It would be great if somehow I could go back and correct every instance with that typo, but editing is now closed for those posts.
Online since 1995.

Calem
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Sun Jul 29, 2012 6:26 am

Re: How to Remove index.php from urls

Post by Calem » Sun Jul 29, 2012 7:02 am

I just wanted to give ppl another heads up. I applied the code shown here by g1smd and logicc on my site and it did the job beautifully. I went to sleep and 12 hrs later checked the site again, to my surprise the hits had dropped hard. It's been a couple of days and the site is getting ~80% less hits. Most of my better keywords have lost a good bit of ranking on Google and others have been deranked completely. :(

I've been checking around and found out 301 redirects do result in individual rank loss

Code: Select all

http://www.stonetemple.com/articles/interview-matt-cutts-012510.shtml
Google recommends doing 1 to 1 redirects to preserve it. Apparently, you also lose out on the trust and authority of inbound links to old URLs. This would be specially painful as the site is over 10 years old.

Reverting the changes doesn't seem to be as simple as going back to the old .htaccess file since Googlebot caches every 301 redirect (permanent, duh) and it could stick for months. Any ideas of what else I could do? Am I missing something here? Hopefully I am. Either way, be very careful (it can't be said enough) of redirect usage.

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 Jul 29, 2012 6:27 pm

It can take ~3 months for the site to be fully re-indexed and re-ranked.

The "remove index.php" redirect should not be used in isolation. It is imperative that the links within the site point to the new format URLs with the redirect being there only for visitors and bots requesting the old URLs found within links in stale SERPs or from other sites or found in their bookmarks.
Online since 1995.

logicc
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Thu Jun 28, 2012 7:07 pm

Re: How to Remove index.php from urls

Post by logicc » Sun Jul 29, 2012 8:39 pm

g1smd wrote:It can take ~3 months for the site to be fully re-indexed and re-ranked.

The "remove index.php" redirect should not be used in isolation. It is imperative that the links within the site point to the new format URLs with the redirect being there only for visitors and bots requesting the old URLs found within links in stale SERPs or from other sites or found in their bookmarks.
Agreed, I used the solution above on new sites mainly but on old ones or static sites ive converted to Joomla i have used 1-1 redirects.

e.g.
domain.com/contact.php ---> domain.com/contact

There are some good extensions for doing this if you don't fancy getting mucky with htaccess. Try these two:

REDJ (FREE) - I used this for redirect old urls to new ones
http://extensions.joomla.org/extensions ... ction/7189


Qlue404 (Free version) - I used this to keep track of any 404s triggered after site move. Any i find i then apply redirects to using REDJ. There is a paid version but ive never used it.
http://www.qlue.co.uk/joomla-extensions ... -page.html


Locked

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