我有一个.htaccess文件,我试图转换,所以它可以在我的Nginx服务器上运行。
我有两个主要问题:
以下是我遇到的问题转换:
Options All -Indexes RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?page_request=$1 [QSA,L]
我尝试了一些在线转换器,但他们似乎并没有工作。
另外,一旦我改变了线,我把它们放在哪里? 我假设我需要将它们放在/etc/nginx/sites-available/
中的mysite.conf
文件中,但是在那个文件中,我只是把它们放在server {}
块中?
非常感谢您给我的任何帮助。
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
做一些nginx的研究,遇到这个,给这个镜头,看看它是否如你所期望的那样工作:
location / { # other code below this line try_files $uri $uri/ /index.php?page_request=$uri; }
基本上,try_files是if语句,它首先尝试常规文件,如果它找不到它,它会尝试作为一个目录,如果它找不到它发送到最后一个参数。
旧
你有没有尝试使用像这样的服务: http : //www.anilcetin.com/convert-apache-htaccess-to-nginx/
它输出:
#ignored: condition 0 #ignored: condition 1 if ($rule_0 = "2"){ rewrite /RewriteRule ^/(.*)$; }
为您提供的数据。
你把它们放在哪里:
server { }
由于这不是一个特定的location
你只是把它放在默认的东西之后。 有经营秩序,所以是的。 如果您有多个位置类型位,它可以位于某个位置的内部。 对于nginx,我可能会把它放在.php位置定义下。