I need to change from apache to Nginx but the .htaccess
doesn' work on the Nginx server.
I got following in my Apache .htaccess
:
RewriteEngine On
# always run through the indexfile
RewriteRule .$ index.php
# don't let people peek into directories without an index file
Options -Indexes
When I put a .htaccess
on the Nginx server, the file gets deleted by the server.
In what kind of file do I have to put the .htaccess
data (name and suffix please) and how should it be rewritten for Nginx and where do I put the file?
I want all subdirectory files to go through my index.php
file so I can include specific files from my index.php
file ...
I have tried something like:
# nginx configuration
autoindex off;
location / {
rewrite .$ /index.php;
}
but it doesn't work. The directory looks something like:
── root
├── folder1
│ └── folder2
│ └── file.php
└── index.php
so if I ask for root/folder1/folder2/file.php
I want the server to load the root/index.php
as I still have the server url request,
I can include the root/folder1/folder2/file.php
from my index.php
It all works on my apache install, but not on the Nginx server. Please help me.
#EDIT:
Turns out the nginx.conf
file has to be above the root folder and is only accessible if you have access to the folders above the root folder. Like server admin access is necessary.
Nginx doesn't have htaccess files. The code needs to go into the nginx config file. Also, try adding the "last" flag to the rewrite:
# nginx configuration
autoindex off;
location / {
rewrite .* /index.php last;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With