Denis Evseev
Denis Evseev

Reputation: 1710

How to rewrite all requests to index.php and sitemap.xml to sitemap.php

Please help, I have already been doing for 2 days and all in vain...

This code works well for rewriting directories and pages to one index.php page

    DirectoryIndex /index.php
    RewriteEngine on
    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d

    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(.*) /index.php [NC,L]

    RewriteRule ^/sitemap.xml sitemap.php [L]

The problem with sitemap.xml as it has to be rewritten into sitemap.php rather than into index.php

Upvotes: 0

Views: 206

Answers (1)

Jonathan
Jonathan

Reputation: 250

You would need to put the sitemap rule before the index rule. Rules are processed from top to bottom and once it hits the index rule (because .* would match sitemap.xml), it would stop processing further because of the [L] flag.

Another option would be to just use php and inside index.php, include sitemap.php; when $_SERVER['REQUEST_URI'] equals sitemap.xml. Same result.

Upvotes: 1

Related Questions