[英]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]
I want separate API entry point for admin module, but rewrite does not work as I want. 我想为管理模块提供单独的API入口点,但是重写无法按我的意愿进行。 What's wrong with rewrite rules?
重写规则有什么问题?
host.com/page - works (/index.php), host.com/page-作品(/index.php),
host.com/admin/page - works (/admin/index.php), host.com/admin/page-作品(/admin/index.php),
host.com/admin/api/section - executes /index.php (but expected /admin/api.php) host.com/admin/api/section-执行/index.php(但需要/admin/api.php)
That is because your rules are looping as admin/.*
pattern also matches admin/api.php
. 那是因为您的规则正在循环,因为
admin/.*
模式也匹配admin/api.php
。 Have rules like this: 有这样的规则:
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.