.htaccess RewriteRule returns a blank page

I have been trying to solve this for more than two hours. I have a personal site that uses .htaccess to manage URLs. It looks like this:

RewriteEngine on RewriteBase / ... RewriteRule ^sklad/?$ index.php?action=sklad RewriteRule ^sklad/user/([0-9]+)?$ index.php?action=sklad&user=$1 RewriteRule ^sklad/folder/(.+)?$ index.php?action=sklad&folder=$1 RewriteRule ^sklad/file/(.+)?$ engine/ajax/sklad.php?file=$1 RewriteRule ^sklad/logout/?$ index.php?action=sklad&op=logout ... RewriteRule ^admin/?$ admin.php RewriteRule ^admin/news/?$ admin.php?action=news 

the first five work fine. admin / works fine. But when I try to access admin / news / , I get a blank page. Errors are not displayed or reported by Apache and are not displayed. admin.php? action = news is working fine.

Both the sklad / and admin / folders physically exist on the server. BUT , when I rename the admin / folder to something else OR , change the last RewriteRule to something like

 RewriteRule ^admin123/news/?$ admin.php?action=news 

I can access admin123 / news / . If this has anything to do with the actual folder existing on the server, then why do the first five rules work? It does not make sense.

I have no ideas, hope someone here helps ...

+4
source share
2 answers

Yes, that triggered news.php ... I renamed the file, and exerything is fine now, thanks! I did not know about this, a rather unobvious mistake (or not?)

This is not a mistake, it seems that content negotiation (via mod_negotiation) is enabled, and it does what you do not need. Negotiations can be enabled using the type map or the MultiViews parameter. Typical tweaks are a little explicit to tweak, so I assume that since you don't know why this is happening, you don’t have a specific type that maps to news.php . So you probably turned on Multivisors . You can disable it, or by removing it from the Options statement:

 # remove this word -----------v Options Indexes FollowSymLinks Multiviews 

It can be anywhere, in your htaccess, server configuration, vhost configuration, in some kind of configuration file, etc. That way, you can also explicitly disable it in your htaccess file (unless you also explicitly install it in the same file):

 Options -Multiviews 
+2
source

I am not good at htaccess and RegExp, but I think admin / news will fall into your first htaccess rule.

  RewriteRule ^admin/?$ admin.php 

Your second admin rule will not continue:

  RewriteRule ^admin/news/?$ admin.php?action=news 

With the same problem that I encountered before.

Try changing your admin.php, echo / print something when there are no params passes. Something like that:

  if($_GET['action']) { echo 'With Parameters'; } else { echo 'No Parameters pass'; } 

It is debugged in this way.

0
source

Source: https://habr.com/ru/post/1444024/


All Articles