Welcome to WebmasterWorld Guest from 54.162.226.212

Message Too Old, No Replies

How can I solve the example.com/index.php problem?

     
9:45 pm on Feb 18, 2011 (gmt 0)

5+ Year Member



searching for my pages indexed by Google, i.e site:www.example.com
I found
www.example.com/
www.example.com/index.php

How can I solve such problem?
11:10 pm on Feb 18, 2011 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Redirect all external requests for index.php to www.example.com/ with a trailing slash. Use a 301 redirect.

If your site is on an Apache webserver, the WebmasterWorld Apache sub-forum has thousands of threads discussing the required code.
2:21 am on Feb 19, 2011 (gmt 0)

WebmasterWorld Administrator 5+ Year Member Top Contributors Of The Month



Also make sure you are internally linking only to www.example.com/
8:39 am on Feb 19, 2011 (gmt 0)

5+ Year Member



I have this code on .htaccess

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.org [NC]
RewriteRule ^(.*)$ http://www.example.org/$1 [L,R=301]
</IfModule>
Options -Indexes

That I copied here when the problem example.com vs www.example.com arised

Can someone of you be so polite to tell me the row I have to add to solve the problem?
8:57 am on Feb 19, 2011 (gmt 0)

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Do this Google search: [site:www.webmasterworld.com redirect index.php htaccess]

You'll find the many threads in our Apache Forum that discuss this issue. It's much better for you to use the technical forum that applies to your server. Never trust a copy/paste solution that someone just hands you.
9:12 am on Feb 19, 2011 (gmt 0)

5+ Year Member



Tedster I already searched for that on this forum, but I did not understand nothing: I do not know what rewrite, rewritecond, $1,... means.
If I start learning it, that will cost me 3 or 4 days of work and you know how important is the time. I am not an expert of such language and I could damage my website more than a suggestion of yours.
If the problem was in php I agree with you for a search here, but I am completely ignorant about htaccess language.
If the problem is the server I can inform you that my server is linux with apache.
Is there some good person that could help me suggesting me the row?
9:29 am on Feb 19, 2011 (gmt 0)

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



If you mess up your htaccess file you may waste more than a few days - you may really trash your site.

I strongly urge you to take personal responsibility for this and not ask others to assume it for you. You can ask questions on the Apache Forum - good people will help you. And what you learn will be yours to know and use for the rest of our life.

There is also a helpful thread in the Hot Topics area [webmasterworld.com], which is always pinned to the top of this forum's index page. See Merging www.example.com/ and www.example.com/index.htm [webmasterworld.com]
9:40 am on Feb 19, 2011 (gmt 0)

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



If you want to take a temporary measure - just until you are confident about the .htaccess fix - you can always add a canonical link tag to the file's <head> section.
9:47 am on Feb 19, 2011 (gmt 0)

5+ Year Member



Tedster you are a kind person and help everyone here in the forum. Please consider I copied my .htaccess 3 years ago here in the forum and I do not know what such code means.
That means I can mess up my htaccess myself more than a memeber of the forum could do.

So please if someone else is reading this post, please help me. I do not have the time to learn htaccess code and this is a simple problem for many of you.
Please guys help me.
10:30 am on Feb 19, 2011 (gmt 0)

10+ Year Member



Here's what I've been using, there's a line there to exclude a folder if you need as well, if not that line can be deleted.


# Redirect index.php to / except /excludethisfolder/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*)index\.php\ HTTP/
RewriteCond %{REQUEST_URI} !^/excludethisfolder/index\.php$
RewriteRule index\.php$ http://www.example.com/%1 [R=301,L]


Be sure to test that it works for your server. The easiest way is to use Firefox, clear the cache and test by going to the urls with index.php added while watching the output with http Live HTTP headers extension. You want to see a 301 redirect.

This should go before the code to redirect non www to www in your htaccess file so that there isn't a double redirect.

Disclaimer
I'm certainly no wiz at this stuff and I think I got that code originally from the apache forum here, so I take no blame or credit for it working or not. That said, it works very well for me on all my sites for all folders (not just the .com/) excluding the ones I need to allow. Be sure to test it thoroughly.
12:17 pm on Feb 19, 2011 (gmt 0)

5+ Year Member



I am using this piece of htaccess code to rewrite / to /index.php

RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^$ http://example.com/index.php [R=301,L]

Note: replace example.com with your URL. The [R=301,L] part does a redirect 301 with a load (L).
2:29 pm on Feb 19, 2011 (gmt 0)

5+ Year Member



Thank you LunaC and johnmoose, I first received a private message from TheMadScientist (many many thanks you saved me 3 days of study), so I used its code that seems working very good.
The code is:
______________________________________
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*index\.php
RewriteRule ^(([^/]+/)*)index\.php$ http://www.example.com/$1 [NC,R=301,L]
RewriteCond %{HTTP_HOST} ^example\.org [NC]
RewriteRule ^(.*)$ http://www.example.org/$1 [L,R=301]
</IfModule>
Options -Indexes
_____________________________________

I knew here is full of nice people. :)

My next question is: Do I have to take some action or will google correct my problem itself?
10:05 pm on Feb 19, 2011 (gmt 0)

WebmasterWorld Administrator 5+ Year Member Top Contributors Of The Month



Just give it a time and it will correct itself.
10:24 pm on Feb 19, 2011 (gmt 0)

5+ Year Member



How much power will I get from this move?
Will I have some benefits in ranking?
10:35 pm on Feb 19, 2011 (gmt 0)

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



It is possible - but these days it's not usually so much, because Google now seems to handle common duplicates like this automatically. However, since you were seeing both versions in the Google index, there is a chance that full link equity was being split in your case.

What you also need to do for the maximum chance at seeing a benefit is make sure that no internal links anywhere on your site still point to index.php. If there are any, then change them to point directly to the domain root.
10:51 pm on Feb 19, 2011 (gmt 0)

5+ Year Member



I am sure I did not linked to index.php, but probably my partner did.
On site:www.example.com I have 241 pages. What is the way to check I have no links to index.php?
Do I have to check my pages one by one? :(
(On webmaster google tool--> internal links--> there are 162 pages but index.php is not in this list)
10:59 pm on Feb 19, 2011 (gmt 0)

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Depending on what software you are using, you could do a search. I use Homesite for some of my development, so I would run an Extended Search operation on the entire set of pages, and then check anything it found. If there were a lot, I'd also use Extended Replace instead of making the changes manually.

If you have the pages all in one folder, you could also use grep. You could probably also run Xenu on your site and see what it finds, then fix any links that it discovers.

[edited by: tedster at 5:03 pm (utc) on Feb 21, 2011]

11:58 pm on Feb 19, 2011 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



I am using this piece of htaccess code to rewrite / to /index.php

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^$ http://example.com/index.php [R=301,L]
</IfModule>

Err. No you're not. There is no rewrite. That is a redirect.

It's also code that will cause you many problems.

Never redirect TO a named index file.

The canonical URL for the site root is www.example.com/ with a trailing slash.

Redirect all requests that include a named index file TO that canonical URL.

The other flaw with that code is that it lets both www.example.com/ and www.example.com/index.php serve yet more duplicate content.

Finally, delete both of the <ifModule> containers. You do want to know if these modules are missing from the server configuration, not just fail silently.
9:40 am on Feb 20, 2011 (gmt 0)

5+ Year Member



Thank you g1smd for the advice, but when you say:
There is no rewrite
Redirect all requests that include a named index file TO that canonical URL.
....
I do not understand nothing.
Could you be so nice to write here the right code for me?
12:07 pm on Feb 20, 2011 (gmt 0)

WebmasterWorld Administrator 5+ Year Member Top Contributors Of The Month



I am using this piece of htaccess code to rewrite / to /index.php


Perhaps the problem is in terminology you are using in this sentence. You do not have to use rewrite to rewrite / to index.php providing that index.php is a default page that is returned when the root is requested.

What you need to do is have a 301 REDIRECT that redirects all external requests for /index.php back to root / I think the .htaccess code TheMadScientist gave you in your message above does this job now.

Internally, you have to link to / (and not to /index.php) so that there is no internal redirect performed. You can use Xenu Link Sleuth to check your site to ensure there are no internal linking to /index.php
2:37 pm on Feb 21, 2011 (gmt 0)

5+ Year Member



aakk9999: that means I can use the code of TheMadScientist?
Because g1smd said "It's also code that will cause you many problems."
4:56 pm on Feb 21, 2011 (gmt 0)

5+ Year Member



@g1smd: point taken, thanks. But the <ifmodule> directive wasn't mine.

@aakk9999: just a matter of words, yep, and I did use a 301.
5:00 pm on Feb 21, 2011 (gmt 0)

WebmasterWorld Senior Member themadscientist is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



Just to make sure proper credit is given for the code in this thread, it actually was only slightly modified code posted here by jdMorgan in the Apache Forum [webmasterworld.com].
5:17 pm on Feb 21, 2011 (gmt 0)

5+ Year Member



Sorry for the misunderstood.
I believed g1smd was referring to the TheMadScientist code, but I realized now he was referring to johnmoose.
Thanks for the code again TheMadScientist.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month