apache2.2 virtual host rewrite rule not matching
-
27-12-2019 - |
Question
I have a very simple rewrite rule in a virtual host:
RewriteRule ^/?([^.]+)\.([^(htm)]+)$ /$1.htm [L,QSA]
RewriteRule ^/(someotherrule)$ /me [L]
Say a call a url: http://myurl.com/test.php
I would expect the the rule to match and the url to be rewritten to http://myurl.com/test.htm
Instead I find this in my rewriteLog:
applying pattern '^/?([^.]+)\\.([^(htm)]+)$' to uri '/test.php'
applying pattern '^/(someotherrule)$' to uri '/test.php'
rewrite '/test.php' -> '/me'
Obviously there is something wrong with my first rewrite rule pattern, but I cannot see what exactly. Probably because I have a knot in my brain from lack of sleep. So if someone would be kind enough to take a second and point out my error, I would really appreciate it.
Solution
You should replace the first rule, resulting in:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^[^.]+\.htm$ [NC]
RewriteRule ^/?([^.]+)\..*$ /$1.htm [L,QSA]
RewriteRule ^/(someotherrule)$ /me [L]
Error is in [^(htm)], meaning that the file extension does not contain characters: (, h, t, m,) , not .htm as you expected.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow