【发布时间】:2017-11-14 13:48:10
【问题描述】:
所以,我的目录结构是这样的;
index.php
location / {
rewrite ^(.*)$ /index.php?params=$1 last;
}
公共/资产/
location /public/assets {
rewrite ^(.*)$ /public/assets/index.php?params=$1 last;
}
所以,我确实需要对这个项目进行 2 次重写,一次用于期望资产的所有内容,一次用于资产。但是使用 Nginx 时出现问题。使用 Nginx 重写 public/assets PHP $_GET 参数如下:
Array
(
[params] => /public/assets/css/syles.css
)
Array
(
[0] =>
[1] => public
[2] => assets
[3] => css
[4] => syles.css
)
这些都是错误的。我不希望 url 传递给 GET。因为在使用 Apache 时,我确实得到了以下结果。使用 Apache 时,代码可以正常工作。
Array
(
[params] => css/styles.css
)
Array
(
[0] => css
[1] => styles.css
)
那么,如何使用 Nginx 配置从 url 中删除这些“额外”参数?或者如果网络服务器是 Nginx,我是否需要使用 PHP 来删除这个额外的参数?我什至不希望将该解决方案作为解决方案提出。
所以,我希望使用 Nginx 获得与使用 Aoache 获得的参数相同的参数。
在使用 Apache 时仅供参考,我将以下 .htaccess 放在 public/assets 下。
RewriteEngine on
RewriteCond %{REQUEST_URI} !/index.php
RewriteRule ^(.*)$ index.php/?params=$1 [NC] #L
【问题讨论】:
标签: php apache .htaccess nginx url-rewriting