sc123
sc123

Reputation: 27

Need htaccess code to rewrite URLs with trailing slash except XML files

Have the following code in .htaccess which rewrites URLs in WordPress from have no trailing slash to having one. For example, www.domain.com/post -> www.domain.com/post/.

Problem is, it's doing it for sitemap.xml which breaks it. How can I exclude .xml files?

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://domain.com/$1/ [QSA,L,R=301]

Upvotes: 0

Views: 671

Answers (1)

Olaf Dietsche
Olaf Dietsche

Reputation: 74108

Just insert another RewriteCond excluding URLs ending in .xml

RewriteCond %{REQUEST_URI} !\.xml$

Upvotes: 2

Related Questions