Search code examples
php.htaccesshttp-redirecttrailing-slash

How can I have an exception for a rule in my .htaccess file?


Probably very easy question but I can't get it to work.

Case: The trailing slash will be removed from the URL by the following htaccess line:

RewriteCond %{request_method} ^GET$
RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteRule ^(.+)$ %1 [L,R=301] # <- this line removes the trailing slash
RewriteRule .* index.php [L]

How can I make an exception for this page: mydomain.com/paypal/ipn/ so it won't do a 301 redirect to: mydomain.com/paypal/ipn


Solution

  • You can create an exception using RewriteCond:

    RewriteCond %{request_method} ^GET$
    RewriteCond %{REQUEST_URI} !^/paypal/ipn/ [NC]
    RewriteRule ^(.+?)/$ %1 [L,R=301,NE]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule . index.php [L]