简体   繁体   English

htaccess返回内部服务器错误

[英]htaccess returns Internal Server Error

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

RewriteRule ^api/list/episode/([^/]*)$ /api/list/episode.php?season=$1 [QSA,NC,L]
RewriteRule ^api/script/([^/]*)/([^/]*)$ /api/script/?season=$1&episode=$2 [QSA,NC,L]

The rewrite rule for the api/list/episode comes up with an Internal Server Error I'm not sure why but the other rule works but I have tried to change api/list/episode的重写规则出现Internal Server Error我不确定为什么,但是其他规则有效,但是我尝试更改

this http://domain/api/list/episode?season=1 这个 http://domain/api/list/episode?season=1

to this http://domain/api/list/episode/1 到此 http://domain/api/list/episode/1

Is it is right for me to place the .htaccess in my root for all directory changes? 对于所有目录更改,将.htaccess放在我的根目录下对吗?

That is because of looping. 那是因为循环。 Change that rule slightly: 稍微更改该规则:

RewriteEngine on 

## If the request is for a valid directory
RewriteCond %{REQUEST_FILENAME} -d [OR]
## If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f [OR]
## If the request is for a valid link
RewriteCond %{REQUEST_FILENAME} -l
## don't do anything
RewriteRule ^ - [L]

RewriteRule ^api/list/episode/([^/]+)/?$ /api/list/episode.php?season=$1 [QSA,NC,L]
RewriteRule ^api/script/([^/]*)/([^/]*)$ /api/script/?season=$1&episode=$2 [QSA,NC,L]

RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php [L]

Try changing the order of your rules. 尝试更改规则的顺序。 The two /api/ rules should go before the routing-to-php-extension rule. 这两个/api/规则应该位于“路由到PHP扩展”规则之前。 This is because %{REQUEST_FILENAME} actually inspects inner path elements so it could mistaken /api/list/episode/1 as /api/list/episode.php/1 as "exists", then you tack on a .php to the end , which makes it: /api/list/episode/1.php . 这是因为%{REQUEST_FILENAME}实际上检查内部路径元素,因此可能会将/api/list/episode/1误认为/api/list/episode.php/1存在,然后将.php /api/list/episode.php/1 到最后 ,使其成为: /api/list/episode/1.php It goes through the rewrite engine and the same thing happens again, and then the loop goes on and on. 它经过重写引擎,并且同样的事情再次发生,然后循环不断进行。

RewriteEngine on 

RewriteRule ^api/list/episode/([^/]*)$ /api/list/episode.php?season=$1 [QSA,NC,L]
RewriteRule ^api/script/([^/]*)/([^/]*)$ /api/script/?season=$1&episode=$2 [QSA,NC,L]

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

You can also try changing you -f check to: 您也可以尝试将-f检查更改为:

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}\.php -f

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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