Forum Moderators: phranque

Message Too Old, No Replies

Duplicate content index.php

Rewrite causing error

         

lizardlips

11:39 pm on Sep 7, 2009 (gmt 0)

10+ Year Member



Hi,

I am having a problem creating a rewrite. I am trying to creat a rewrite that will have index.php. index.htm, index.html and index.html all go to the root url www.xyz. com

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

and it works but when I tried to login to my site map generator whic is /sitemap/index.php it will not work with that rewite.

Any ideas?

[edited by: jdMorgan at 2:15 am (utc) on Sep. 8, 2009]
[edit reason] example.com [/edit]

jdMorgan

2:15 am on Sep 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just exclude that directory from the rule:

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

Note that $1 contains the directory-path matched by the RewriteRule pattern (and yes, it is defined and available to the RewriteCond). :)

Jim

lizardlips

3:34 am on Sep 8, 2009 (gmt 0)

10+ Year Member



Hi jd,

Thank you for your reply. Is there anyway to add the other three extensions (index.htm, index.html and index.html ) to this rewrite or should I create three more?

jdMorgan

4:16 am on Sep 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use the 'local OR' and the 'zero or one' quantifier in the regular expressions sub-patterns for the filetype, e.g. replace "php" in both lines with "(php¦html?)"

But note that you must change the broken pipe "¦" character to a solid pipe character before use; Posting on this forum modified the pipe characters.

See the resources cited in our Apache Forum Charter for more information.

Jim