简体   繁体   中英

Codeigniter Apache to nginx rewrite

I just transferred my website from GoDaddy (Apache) to DigitalOcean (Nginx/LEMP). The Web site was developed using PHP/CodeIgniter. I am only able to see the first page (index.php). It works if I provide the full URL of any file, but I cannot access URL rewrites. Looks like some issue with my .htaccess file...

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    Options -Indexes
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

Any help or link/tutorial on how to move from Apache to Nginx will be helpful.

I figured it out.

Your whole rewrite rule converted to one line

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

to

location / {
    try_files $uri $uri/ /index.php?$args;
}

The update/edit your default nginx file by

nano /etc/nginx/sites-available/default

and restart the service

sudo nginx service restart

Thanks for thos who looked and replied.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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