简体   繁体   中英

Configure Nginx to hide index.php and redirect to

Is possible to do this same code (Apache .htaccess) on Nginx Server?

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

The most important for me in this case, is preservs a $_SERVER['QUERY_STRING'] with all contents after a localhost/root/$query_string

I'm developing a framework PHP using HHVM, the only thing that I want is hide a "index.php" or "index.hh", without redirect to 404 Nginx or load a index.php/index.php inside my nginx's root projects folders

Have you tried using try_files ?

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

Then, configure your index.php to catch your query string with $_SERVER['QUERY_STRING'] as stated above.

Check out the WordPress nginx configuration for an example: https://codex.wordpress.org/Nginx

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