2

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;
}

1 Answer 1

2

UPDATE

Doing some nginx research, came across this, give this a shot and see if it works as you expect:

location / {
    # other code below this line
    try_files $uri $uri/ /index.php?page_request=$uri;
}

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:

#ignored: condition 0
#ignored: condition 1
if ($rule_0 = "2"){
rewrite /RewriteRule ^/(.*)$;
}

For the data you provided.

Where you put them is inside the:

server {

}

Since this is not for a specific location you 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.

Sign up to request clarification or add additional context in comments.

12 Comments

Yes, I tried this site, but this code doesn't work. In fact, the commented "ignored: condition 0" means the convert is ignoring lines in my code. Running this code yields the error: nginx: [emerg] invalid variable name in /etc/nginx/sites-enabled/atr3.com.conf:38.
Can you post the atr3.com.conf? It would make it a bit easier to see what may be going wrong.
I just edited my question, added it in. (subdomain.domain.tld is in place of the actual data)
Also, I also know the code from the converter can't work because it needs to be sending the string as a page_request $_GET variable to PHP.
Hmm... That seems like it makes sense now, but I'm still getting 404 errors while trying this.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.