I have an .htaccess file that I’m trying to convert so it can be run on my Nginx server.
I’m having two primary problems:
1. I’m not sure how to convert some lines
2. I don’t know where to put the Nginx configuration code
Here are the lines I’m having issues converting:
Options All -Indexes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page_request=$1 [QSA,L]
I’ve tried some online converters, but they don’t seem to be working.
Also, once I’ve converted the lines, where do I put them? I assume I need to place them in the mysite.conf file in /etc/nginx/sites-available/, but within that file, do I just put them within the server {} block?
Thanks a lot for any help you can give me.
Edit: Here’s the conf file
server {
listen 0.0.0.0:80;
server_name www.subdomain.domain.tld subdomain.domain.tld;
access_log /var/log/subdomain.domain.tld.log;
location / {
root /srv/www/subdomain.domain.tld/public_html;
index index.html index.php;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/subdomain.domain.tld/public_html$fastcgi_script_name;
}
try_files $uri $uri/ /index.php?page_request=$uri;
}
UPDATE
Doing some nginx research, came across this, give this a shot and see if it works as you expect:
Basically the try_files is the if statement, it tries the regular file first, if it cannot find it, it tries it as a directory, if it cannot find that it sends it to the last argument.
OLD
Have you tried using a service like: http://www.anilcetin.com/convert-apache-htaccess-to-nginx/
It outputs:
For the data you provided.
Where you put them is inside the:
Since this is not for a specific
locationyou would just put it after the default stuff. There is order of operations to be had, so yea. It can be inside of a location, if you have more than one location type bit. For nginx, I would probably put this under the .php location definition.