1

I have an htaccess file utilising Rewrite Engine. I have attempted to set it up for individual pages to remove the .php extension.

I have found this being applied to an image called logout.png as well though. If the logout.png image is anywhere on the page, the user is logged out as if the logout.php page is being loaded somewhere in the background.

Here is my code:

RewriteEngine on
RewriteRule login login.php [L]
RewriteRule logout logout.php [L]

Is there something there I can change to make sure it's only applied to logout.php and not logout.png?

SystemX17
  • 3,637
  • 4
  • 25
  • 36
  • 1
    wrap it in 'whole-match boundaries': `^logout$` (I don't know the correct term for this, sorry...) – Jeff Feb 17 '18 at 12:16
  • 1
    https://stackoverflow.com/questions/6298566/regex-match-whole-string – Jeff Feb 17 '18 at 12:18
  • Sweet, so as I understand it then - it's because it is matching the [.png] part as well. Including it. But adding the ^ and $ mean nothing before and nothing after. Thanks for your help. If you can post this as an answer I will accept it. – SystemX17 Feb 17 '18 at 12:21

2 Answers2

2

If you want a regular expression to only match if the whole string matches wrap it in start and end delimiters:

RewriteRule ^logout$ logout.php [L]
Jeff
  • 6,895
  • 1
  • 15
  • 33
1
RewriteEngine on
RewriteRule login login.php
RewriteRule logout logout.php [L]
RewriteCond %{REQUEST_URI} !^/logout\.png$ [NC]

Try this?

If all things fail you can always rename files

Richard
  • 325
  • 7
  • 23