WordPress blogs show the same duplicate content for https://www.askapache.com/index.php and https://www.askapache.com/. If you've read about using a robots.txt file for WordPress SEO, than you already understand this setup results in Duplicate Content penalties being levied against your Blog and Web Site by Search Engines.

A common request is to be able to remove or redirect the index.php from appearing in the url. This is possible only with server-side technology like .htaccess configuration files or your main server config by using the Mod_Rewrite Rewrite Module.

Table of Contents

  1. Introduction
    1. The Redirect Fix
      1. .htaccess mod_rewrite code
        1. askapache.com/index.php
        2. askapache.com/blog/index.php
      2. More Info

The Redirect Fix

The fix is a bit of clever .htaccess code utilizing mod_rewrite to only redirect index.php if the request for /index.php came from a client (e.g. browser or web robot), and not if the request is an internal redirect that apache does when / is requested so that it can serve the contents of index.php.

.htaccess mod_rewrite code

askapache.com/index.php

Options +FollowSymLinks
DirectoryIndex index.php

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.php HTTP/
RewriteRule ^index.php$ https://www.askapache.com/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

askapache.com/blog/index.php

Options +FollowSymLinks
DirectoryIndex index.php

RewriteEngine On
RewriteBase /blog/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /blog/index.php HTTP/
RewriteRule ^index.php$ https://www.askapache.com/blog/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]

More Info

The problem with this is that any request for "/" is internally rewritten to index.php by Apache mod_dir if you have index.php in the DirectoryIndex list (the usual set-up), so it's difficult to avoid an infinite loop.

Redirect index.php to root - AskApache

Charles Torvalds
9 Aug 2007

  • Site Map WireShark GNU Non-GNU Tor Project cURL TLDP - Documentation
  • Htaccess Files Hacking Htaccess Javascript Linux Optimization PHP Security Shell Scripting WordPress
  • Base64 Image Converter Raw HTTP Header Debugger Graphical ASCII Text Generator Mac Address Vendor Lookup Who Am I – Your IP Information Request Method Security Scanner .htpasswd file Generator Compress CSS DNS Tracer
Copyright © 2025 AskApache
  • Site Map
  • Htaccess Files
  • Hacking
  • Htaccess
  • Javascript
  • Linux
  • Optimization
  • PHP
  • Security
  • Shell Scripting
  • WordPress
  • Base64 Image Converter
  • Raw HTTP Header Debugger
  • Graphical ASCII Text Generator
  • Mac Address Vendor Lookup
  • Who Am I – Your IP Information
  • Request Method Security Scanner
  • .htpasswd file Generator
  • Compress CSS
  • DNS Tracer
Exit mobile version