6

I have two scripts:

  • xmlsitemap.php (Google XML sitemap)
  • sitemap.php (GUI user friendly sitemap)

I want to achieve this with rewrite rules:

Rewrite to site.com/sitemap.php
site.com/sitemap
site.com/sitemap/

Rewrite to site.com/xmlsitemap.php
site.com/sitemap.xml

Here is what I have tried. The problem is it's rewriting sitemap.xml to sitemap.php (GUI).

Options +FollowSymlinks
RewriteEngine On

RewriteRule sitemap.xml xmlsitemap.php
RewriteRule sitemap sitemap.php

# also tried using [L] option on both
Chris
  • 977
  • 4
  • 11
  • 12
  • What does not work? Have you started with a single rewrite for a single script and you got it to work? – hakre Jul 06 '11 at 08:32
  • It rewrites site.com/sitemap.xml to sitemap.php which is wrong. sitemap.xml should rewrite to xmlsitemap.php. Both rules work when the other is commented out, the problem is they don't work together. – Chris Jul 06 '11 at 08:53

1 Answers1

11

First of all, re-add the [L] flag. Second, if one rule supersedes the other, check your rewrite rules regex to make them better matching, like the whole request:

RewriteRule ^sitemap\.xml$ xmlsitemap.php [L]
RewriteRule ^sitemap$ sitemap.php [L]

The L flag will prevent to run additional rules if one already matched (but still can trigger an internal redirect, see as well the END flag instead of the L flag).

Community
  • 1
  • 1
hakre
  • 193,403
  • 52
  • 435
  • 836
  • Thanks, works. I've just added another rule with a trailing / to accomodate site.com/sitemap/ – Chris Jul 06 '11 at 10:19