Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
856 views
in Technique[技术] by (71.8m points)

apache - Converting .htaccess to nginx (mod_rewrite)

I've got the following .htaccess file for my apache:

<IfModule mod_rewrite.c>
 ?Options +FollowSymlinks    
# Options +SymLinksIfOwnerMatch
 ?RewriteEngine On
 ?RewriteBase /
 ?RewriteRule ^$ ? ? ? ? ?index.php ? ? ? [L]
 ?RewriteCond %{REQUEST_FILENAME} ? ? ? ? !-f
 ?RewriteCond %{REQUEST_FILENAME} ? ? ? ? !-d
 ?RewriteRule (.*) ? ? ? ?index.php?page=$1 ?[QSA,L]
</IfModule>

Suddenly I had to change my webserver to nginx and I don't know why, but the mod rewrite is not working.

I used an online 'converter' to convert it, so I've got the following:

location / {
  rewrite ^/$ /         index.php       break;
  if ($request_filename ~         !-f){
    rewrite ^(.*)$ /       index.php?page=$1   break;
  }
}

Could you help me what's wrong?

Thanks in advance, Marcell

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

http://web.archive.org/web/20180812021847/https://blog.martinfjordvald.com/2011/02/nginx-primer-2-from-apache-to-nginx/

Everything is inside. No more .htaccess, no more complex rules use try_files.

EDIT: And if it is not obvious, do not trust online converters.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...