使用.htaccess进行Apache到Nginx转换的问题

时间:2015-07-17 06:27:06

标签: php apache .htaccess nginx

我正在尝试将Apache网站迁移到完全由PHP-FPM驱动的Nginx。

但是当我尝试转换为.htaccess文件设置的以下复杂规则时,所有使用在线转换器的尝试都失败了。

有没有人可以帮我解决这个问题?

#ModPagespeed on
Options -indexes
AddOutputFilterByType DEFLATE text/html text/plain text/xml
# BEGIN Rewrite
<IfModule mod_rewrite.c>
RewriteEngine on 
RewriteBase /

RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

RewriteCond %{THE_REQUEST} \s/+(?:index\.php)?\?search=([^\s&]+) [NC]
RewriteRule ^ /%1/? [R=302,L,NE]
## replace of space with -
# executes **repeatedly** as long as there are more than 1 spaces in URI
RewriteRule "^(\S*) +(\S* .*)$" /$1-$2 [L,NE]
# executes when there is exactly 1 space in URI
RewriteRule "^(\S*) (\S*)$" /$1-$2? [L,R=302,NE]


RewriteRule ^search/([^/]+)/page/([^/]+)$ index.php?search=$1&page=$2
RewriteRule ^article/([^/]+)/([^/]+)/$ index.php?layout=article&id=$1

RewriteRule ^adwords/([^/]+)$ adwords/$1 [L]

RewriteRule ^images/([^/]+)$ images/$1 [QSA,L]
RewriteRule ^images/([^/]+)/([^/]+)$ images/$1/$2 [QSA,L]

RewriteRule ^ajax/([^/]+)$ ajax/$1 [QSA,L]

RewriteRule ^info/([^/]+)$ info/$1 [QSA,L]
RewriteRule ^reports/([^/]+)$ reports/$1 [QSA,L]

RewriteRule ^css/([^/]+)$ css/$1 [QSA,L]
RewriteRule ^css/([^/]+)/([^/]+)$ css/$1/$2 [QSA,L]

RewriteRule ^includes/([^/]+)$ includes/$1 [QSA,L]
RewriteRule ^includes/([^/]+)/([^/]+)$ includes/$1/$2 [QSA,L]

RewriteRule ^reports/([^/]+)$ reports/$1 [QSA,L]

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ ?search=$1 [QSA,L]
</IfModule>
# END Rewrite

如果我用下面的转换器转换它我会得到错误 http://www.anilcetin.com/

Invalid nginx configuration: nginx: [emerg] invalid variable name in /var/www/vhosts/system/example.com/conf/vhost_nginx.conf:12 nginx: configuration file /etc/nginx/nginx.conf test failed 

0 个答案:

没有答案