简体   繁体   中英

Apache .htaccess file to Nginx conf file

I have recently moved from an Apache server to an Nginx one. I wasn't even aware of the fact you couldn't use .htaccess files on nginx at first, i've looked into this a little but I'm finding it very confusing on how to convert the rules of a .htaccess file to be usable on nginx. If someone could help me out a little I would really appreciate it!

Here is my .htaccess file:

DirectoryIndex index.php
Options -MultiViews

RewriteEngine on

RewriteCond %{THE_REQUEST} /index\.php\?page=([^\s&]*)[&\s] [NC]
RewriteRule ^ /page/%1? [R=302,L]

RewriteCond %{THE_REQUEST} /index\.php\?regiment=([^\s&]*)[&\s] [NC]
RewriteRule ^ /regiment/%1? [R=302,L]

RewriteCond %{THE_REQUEST} /error\.php\?error=([^\s&]*)[&\s] [NC]
RewriteRule ^ /error/%1? [R=302,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^page/([^/]+)/?$ /index.php?page=$1 [L,QSA]
RewriteRule ^regiment/([^/]+)/?$ /index.php?regiment=$1 [L,QSA]
RewriteRule ^error/([^/]+)/?$ /error.php?error=$1 [L,QSA]

ErrorDocument 404 /error.php?error=404
ErrorDocument 403 /error.php?error=403

Thanks to everyone who helps in advance!

I'm use the website to converter : http://www.winginx.com/en/htaccess

works for you too?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM