How to get rid of "mydomain/index.php?mypage"

General questions about CMSimple
svasti
Posts: 1651
Joined: Wed Dec 17, 2008 5:08 pm

How to get rid of "mydomain/index.php?mypage"

Post by svasti » Thu Aug 14, 2014 11:33 am

After having made a website and searching it in Google I find that Google answers with 2 sites:
  1. http://www.mydomain.de/index.php?pageX/subpageY
  2. http://www.mydomain.de/?pageX/subpageY
Why that?

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: How to get rid of "mydomain/index.php?mypage"

Post by cmb » Thu Aug 14, 2014 12:03 pm

Because it is possible to access the page either way (i.e. with or without index.php), and apparently different links are available somewhere. To rewrite all requests with an explicit index.php, you can use the following rewrite rule in .htaccess in the domain root (requires an Apache server and mod_rewrite):

Code: Select all

RewriteEnginge On
RewriteCond %{REQUEST_URI} /index\.php
RewriteRule ^index\.php / [QSA,L,R=301]
Please test with R=302 at first, and change it to R=301 only if it works.

BTW: http://www.my-domain.de/ shows a blank screen! :shock:
Christoph M. Becker – Plugins for CMSimple_XH

svasti
Posts: 1651
Joined: Wed Dec 17, 2008 5:08 pm

Re: How to get rid of "mydomain/index.php?mypage"

Post by svasti » Thu Aug 14, 2014 1:01 pm

cmb wrote:Because it is possible to access the page either way (i.e. with or without index.php),
I would think this is a serious flaw. The possibility to access the page either way means duplicated content which should be avoided.
I think this is a point not only for my case but for everybody.

But how does Google come to link to the index.php? Usually one never uses such explicit links.
cmb wrote:To rewrite all requests with an explicit index.php,
No, no, no, certainly not, I don't want uselessly elongated links. I just want this index.php to disappear from the Google listing. Normal people would never use it.

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: How to get rid of "mydomain/index.php?mypage"

Post by cmb » Thu Aug 14, 2014 1:45 pm

svasti wrote:I would think this is a serious flaw. The possibility to access the page either way means duplicated content which should be avoided.
I'm not sure whether this case is regarded as DC by search engines. Anyway, we can't ship a prepared .htaccess, because that would require mod_rewrite--otherwise the site might not be accessible. And a worse case of DC is http://www.example.com/ vs. http://example.com/. These issues should be documented in the Wiki.

And of course some kind of Canonical Link would be helpful. For instance, http://3-magi.net/index.php generates:

Code: Select all

<link rel="canonical" href="http://3-magi.net/">
svasti wrote:But how does Google come to link to the index.php? Usually one never uses such explicit links.
Maybe the core or a plugin has created such a link on a page. Maybe the site (containing index.php) has been submitted somewhere. Maybe somebody has deliberately posted such a link somewhere. Lots of possibilities.
svasti wrote:
cmb wrote:To rewrite all requests with an explicit index.php,
No, no, no, certainly not, I don't want uselessly elongated links. I just want this index.php to disappear from the Google listing. Normal people would never use it.
That is a misunderstanding. The .htaccess code is meant remove index.php from incoming requests. The 301 status code shall cause Google to correct the links (may take some time, though).
Christoph M. Becker – Plugins for CMSimple_XH

svasti
Posts: 1651
Joined: Wed Dec 17, 2008 5:08 pm

Re: How to get rid of "mydomain/index.php?mypage"

Post by svasti » Thu Aug 14, 2014 1:54 pm

Sorry I may not have understood correctly.
Anyhow I implemented your suggestion and got:

Code: Select all

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, [no address given] and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.2.22 Server at www.sachverstand-bauhandwerk.de Port 80

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: How to get rid of "mydomain/index.php?mypage"

Post by cmb » Thu Aug 14, 2014 1:59 pm

Do you have checked (in the PHP Info) that mod_rewrite is enabled?
Christoph M. Becker – Plugins for CMSimple_XH

svasti
Posts: 1651
Joined: Wed Dec 17, 2008 5:08 pm

Re: How to get rid of "mydomain/index.php?mypage"

Post by svasti » Thu Aug 14, 2014 2:16 pm

I went through it and nowhere there is mod_rewrite
Seems no to be enabled. I'll see if it can be enabled.

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: How to get rid of "mydomain/index.php?mypage"

Post by cmb » Thu Aug 14, 2014 2:39 pm

svasti wrote:I went through it and nowhere there is mod_rewrite
Seems no to be enabled. I'll see if it can be enabled.
Yes, that's probably best. You may want to consider to add a rewrite rule to redirect from http://example.com/ to http://www.example.com/:

Code: Select all

RewriteEnginge On

RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]


RewriteCond %{REQUEST_URI} /index\.php
RewriteRule ^index\.php / [QSA,L,R=301]
(test with R=302 first)

On further consideration, it should be possible to add the /index.php -> / redirect to CMSimple_XH (the www redirect might be much harder, if generally possible at all). Basically, it could be detected if $sn ends with "index.php" and then sending the appropriate Location header and terminating the script. I'll do some experiments later.

However, if we would do this for XH 1.6.4, I suggest to make it optional as requesting index.php directly has its uses (manual maintenance mode: index.html in the root).

PS: http://www.mattcutts.com/blog/seo-advic ... alization/ might be a good read. Haven't checked it yet.
Christoph M. Becker – Plugins for CMSimple_XH

svasti
Posts: 1651
Joined: Wed Dec 17, 2008 5:08 pm

Re: How to get rid of "mydomain/index.php?mypage"

Post by svasti » Thu Aug 14, 2014 2:57 pm

I just tried your .htaccess on my own server (different hoster), where mod_rewrite can be found in the php-info, and got the same answer. Hm, I guess something's wrong somewhere.

This funny /index.php in the address can be used on all CMSimple_XH websites. Strange, how could Google find that? Normally there are no links going via this index.php

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: How to get rid of "mydomain/index.php?mypage"

Post by cmb » Thu Aug 14, 2014 3:07 pm

svasti wrote:I just tried your .htaccess on my own server (different hoster), where mod_rewrite can be found in the php-info, and got the same answer. Hm, I guess something's wrong somewhere.
I had tested this on localhost (Apache 2.4.4) as well as on 3-magi.net (Apache 2.?). You might have to debug the issue.
Christoph M. Becker – Plugins for CMSimple_XH

Post Reply