繁体   English   中英

一些重写规则不起作用(.htaccess)

[英]Some of rewrite rules are not working (.htaccess)

RewriteEngine on

RewriteRule ^admin/api/(.*)$ admin/api.php?method=$1 [QSA,L]
RewriteRule ^admin/(.*)$ admin/index.php [QSA,L]

RewriteRule ^api/(.*)/$ api.php?method=$1 [QSA,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_URI} !\.(?:css|js|jpg|png|gif|svg|eot|ttf|woff)$ [NC]
RewriteRule (.*) index.php [QSA,L]

我想为管理模块提供单独的API入口点,但是重写无法按我的意愿进行。 重写规则有什么问题?

host.com/page-作品(/index.php),

host.com/admin/page-作品(/admin/index.php),

host.com/admin/api/section-执行/index.php(但需要/admin/api.php)

那是因为您的规则正在循环,因为admin/.*模式也匹配admin/api.php 有这样的规则:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^admin/api/([^.]+)$ admin/api.php?method=$1 [QSA,L]

RewriteRule ^admin/([^.]+)$ admin/index.php [L]

RewriteRule ^api/([^.]+)/$ api.php?method=$1 [L]

RewriteCond %{REQUEST_URI} !\.(?:css|js|jpg|png|gif|svg|eot|ttf|woff)$ [NC]
RewriteRule (.*) index.php [L]

暂无
暂无

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

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