1
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]

的重写规则提出api/list/episode了一个Internal Server Error我不知道为什么但另一个规则有效但我试图改变

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

对此 http://domain/api/list/episode/1

我将 .htaccess 放在我的根目录中以进行所有目录更改是否正确?

4

2 回答 2

1

那是因为循环。稍微更改该规则:

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]
于 2013-11-13T15:12:38.377 回答
1

尝试更改规则的顺序。这两个/api/规则应该在 routing-to-php-extension 规则之前。这是因为%{REQUEST_FILENAME}实际上检查了内部路径元素,因此它可能被误认为/api/list/episode/1/api/list/episode.php/1“存在”,然后您将 .php添加到末尾,这使得它:/api/list/episode/1.php。它通过重写引擎,同样的事情再次发生,然后循环继续。

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

您也可以尝试将 -f check 更改为:

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}\.php -f
于 2013-11-13T15:13:00.650 回答