【发布时间】:2020-09-22 04:46:27
【问题描述】:
我尝试在site 上进行转换,但我没有成功。 我需要为 Nginx 代码转换 .htacess 代码。 我的 .htacess 代码:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?url=$1 [PT,L,QSA]
ErrorDocument 400 error.html?err=404
ErrorDocument 401 error.html?err=401
ErrorDocument 403 error.html?err=403
ErrorDocument 404 error.html?err=404
ErrorDocument 500 error.html?err=500
ErrorDocument 503 error.html?err=503
</IfModule>
我的 nginx 代码是:
server {
listen 80;
server_name mysite.mysite.com.*;
index index.php;
root /home/mysite1/public_html/mysite/webapp/;
client_max_body_size 5M;
if (!-e $request_filename){
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}
location / {
try_files $uri $uri/ index.php?url=$uri&$query_string;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm/www.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include /etc/nginx/fastcgi.conf;
}
}
我的php代码是:
<?php
define('APP_PATH', ROOT . DS . 'app' . DS);
define('CFG_PATH', ROOT . DS . 'config' . DS);
define('LIB_PATH', __DIR__ . DS . 'lib' . DS);
define('RES_PATH', ROOT . DS . 'resources' . DS);
define('TMP_PATH', ROOT . DS . 'tmp' . DS);
define('VND_PATH', ROOT . DS . 'vendor' . DS);
$url = isset($_GET['url']) ? $_GET['url'] : '';
require_once(VND_PATH . 'autoload.php');
require_once(CFG_PATH . 'config.php');
require_once(CFG_PATH . 'routing.php');
require_once(__DIR__ . DS . 'doctrine.php');
require_once(__DIR__ . DS . 'autoloader.php');
Cache::createDirs();
session_start();
$dfgfw = new DFGFW();
$dfgfw->gzipOutput() || ob_start("ob_gzhandler");
$dfgfw->setReporting();
$dfgfw->removeMagicQuotes();
$dfgfw->exec();
访问该网站的作品。 mysite.mysite.com
路线系统不工作。 mysite.mysite.com/history
我的 Nginx 出了什么问题,如何使用 Codeigniter 内部路由系统?
【问题讨论】:
-
完全摆脱
if块,您的location块使用try命令执行此操作,该命令说“尝试将此请求作为文件,然后是目录,然后传递它到index.php"
标签: php apache .htaccess codeigniter nginx