Apache: cannot rewrite sitemap.xml as sitemap.php

1.1k views Asked by At

I have the following .htaccess file in the root (htdocs/johndoe) of my web document tree where index.php is found:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ index.php?lang=$1&menu1=$2&menu2=$3 [QSA,NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?lang=$1&menu1=$2 [QSA,NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?lang=$1 [QSA,NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule sitemap.xml sitemap.php

Not sure what I am doing wrong, but when I access:

http://localhost/johndoe/sitemap.xml

it just loads my index.php instead of calling sitemap.php. Where am I going wrong? Thanks.

1

There are 1 answers

0
John Sonderson On

Moving the rule:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule sitemap.xml sitemap.php

to the top of the .htaccess file just after the RewriteEngine on directive seemed to solve my problem.