Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 将重写从htaccess转换为nginx_.htaccess_Nginx - Fatal编程技术网

.htaccess 将重写从htaccess转换为nginx

.htaccess 将重写从htaccess转换为nginx,.htaccess,nginx,.htaccess,Nginx,我有.htaccess: RewriteRule ^thumb/(.*)x(.*)/r/(.*) thumb.php?w=$1&h=$2&src=$3 RewriteRule ^medias/(.*) files.php?file=$1 RewriteRule ^sitemap\.xml$ index.php [L] RewriteRule ^(.*)(\.html|\.htm)$ index.php [L] RewriteRule ^(.*)(\.rss|\.atom|\.t

我有
.htaccess

RewriteRule ^thumb/(.*)x(.*)/r/(.*) thumb.php?w=$1&h=$2&src=$3
RewriteRule ^medias/(.*) files.php?file=$1

RewriteRule ^sitemap\.xml$ index.php [L]
RewriteRule ^(.*)(\.html|\.htm)$ index.php [L]
RewriteRule ^(.*)(\.rss|\.atom|\.txt)$ index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ index.php [L]
Nginx重写是:

rewrite ^/thumb/(.*)x(.*)/r/(.*) /thumb.php?w=$1&h=$2&src=$3;
rewrite ^/medias/(.*) /files.php?file=$1;
rewrite ^/sitemap\.xml$ /index.php break;
rewrite ^/(.*)(\.html|\.htm)$ /index.php break;
rewrite ^/(.*)(\.rss|\.atom|\.txt)$ /index.php break;
访问类别时,我会看到主页

需要帮忙吗


感谢

Nginx的配置通常有点不同,有很多位置块

我很难测试这一点,但这可能会帮助您前进:

# Nginx excludes the query string (part after the ?) before trying to match
location = /index.php {
    # FastCGI PHP stuff here
}

location ~ ^/thumb/([^/]+)x([^/]+)/r/([^/]+) {
    rewrite ^ /thumb.php?w=$1&h=$2&src=$3 break;
}

location ~ ^/medias/(.*) {
    rewrite ^ /files.php?file=$1 break;

    # To be honest I would try to avoid serving files through PHP. It's much more efficient to let Nginx serve them directly with something like:
    root /path/to/media's/parent;
    try_files $uri =404;
}

location ~ ^/sitemap\.xml$ {
    rewrite ^ index.php break;
}

location ~ (\.html|\.htm|\.rss|\.atom|\.txt)$ {
    rewrite ^ index.php break;
}

# Catch-all
location / {
    try_files $uri index.php;
}

您必须使用正则表达式测试扩展,这意味着它们都必须使用正则表达式。这是因为带有正则表达式的块在最长前缀块之前求值。请务必阅读示例以获得更好的解释。

当“访问类别”时,url是什么?您好,它是:/CategoryName/index.1.html