简体   繁体   中英

nginx simple .htm to .php rewrite rule does not work

I have this simple rewrite rule:

rewrite ^/category.htm /category.php last;

and it does not work and the site gives 404 error.

This is happening only on a specific server, while this rule works fine everywhere else.

The important thing is that if I remove the dot (.) from the rule and use an underscore for eg, it works fine.

So I think it is some issue with escaping the dot (.)

I also tried this but it does not work either:

rewrite ^/category\.htm /category.php last;

Can anyone please help!

I'm not 100%, and I've got no way of testing it right now, but I think the period needs to be in brackets. You may also need a dollar sign. So, something like:

rewrite ^/category(.)htm$ /category.php last;

I can't promise it's the correct answer, but I'm pretty sure you're on the right track by trying to escape the period.

I found the issue by emptying out the whole file and then adding it back line by line...

Thus I found out exactly where the problem was and it was an external file that was messing the rules in this file...

My advice to everyone, if you are ever stuck in such a situation, try commenting all the includes first and then you can safely say that whatever is happening its from your code and you can fix it then

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM