I'm using URL rewriting to make my url http://example.com/foo/bar/ to http://example.com/index.php/foo/bar.

I'm not linking the index.php/.. url anywhere, but for some reasons, some users arrives to the index.php url.

In Google analytics, I have a lot of duplicates that are quite annoying to follow up the traffic.

I've watched the Advanced filters but I'm struggling to make it works fine.

Any regex and google analytics pro to help me out ?

  • I would run Xenu and check all the links on the page to make sure none are linking to index.php.... I've seen this also happen with shoty PHP programming. IMHO the /index.php/foot/bar/ looks a bit off you should focus on getting example.com/foo/bar/ as your index, first by fixing your code, then set canonical tags as needed. Tell Google in Webmaster Center what your main URL is. – Anagio Oct 20 '12 at 17:15

You've got the right idea using the advanced filter. If you want to remove the index.php from all entries you should use this:

Remove index.php from Analytics URL's

Google Analytics Advanced Filter 1 http://www.customclicks.co.uk/_images/pages-resource-articles/google-analytics-advanced-filter-1.png

Alternatively, if you want to add the index.php to all entries:

Google Analytics Advanced Filter 2 http://www.customclicks.co.uk/_images/pages-resource-articles/google-analytics-advanced-filter-2.png

You can read this article for more information


How do you know it's a web visitor (as in a human). You will often find that these results are masked by robots and crawlers! Just because you're linking the page within your site today doesn't mean that you didn't in the past (which could be indexed by a search engine or even on a forum or similar) doesn't mean it can't be found.

  • Sure ! By the way my question is how to make Google analytics understand that this is the same URL, not why there is thoses URL. – magnetik Jul 17 '12 at 12:01
  • Does this help: webmasters.stackexchange.com/questions/31796/… – Dave Jul 18 '12 at 12:41
  • Do you know, for sure, if Google Analytics does take this into account ? I don't think so. Moreover, there is a solution to add a filter into GA to make this work, I just don't know how (and that's my question) – magnetik Jul 18 '12 at 15:53

If you have a rewrite rule to rewrite TO the index.php script when "index.php" isn't in the URL, you can have another rewrite rule to redirect away from it when "index.php" is in the URL. I asked on StackOverflow about the mechanics of doing this. You need to use an environment variable with such rewrite rules to prevent infinite loops. Your two rewrite rules would need to look something like this:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index\.php
RewriteRule (.*) /index.php/$1 [L,E=LOOP:1]

RewriteCond %{ENV:REDIRECT_LOOP} !1
RewriteRule ^index\.php(\/.*)$ $1 [R,L]

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.