linux - 将 "handmade"htaccess 移至 nginx 配置

标签 linux wordpress .htaccess nginx

主要问题是由 https://winginx.com/htaccess 转换的代码不管用。当尝试打开页面时,它只有白皮书,没有任何调试消息。

已经有 nginx 配置:

server {

    location / {
        try_files $uri $uri/ /index.php?$args;
                rewrite ^/course-track/* https://website.com/profile/? redirect;
                rewrite ^/course-category/* https://websitw.com/profile/? redirect;
    }
        location /extra-online-testing/ {
                rewrite ^(.*)$ https://website.com/tests/extra-online-testing/ redirect;
        }

        location = /my-courses/ {
               rewrite ^(.*)$ https://website.com/profile/? redirect;
        }
        location = /courses/ {
         rewrite ^(.*)$ https://website.com/profile/? redirect;
        }
}

htaccess:

RewriteEngine On

RewriteCond %{REQUEST_URI} ^/my-courses/$
RewriteRule ^.*$ https://website.com/profile/? [R=301,L]

RewriteCond %{REQUEST_URI} ^/course-track/*
RewriteRule ^.*$ https://website.com/profile/? [R=301,L]

RewriteCond %{REQUEST_URI} ^/courses/$
RewriteRule ^.*$ https://website.com/profile/? [R=301,L]


RewriteCond %{REQUEST_URI} ^/course-category/*
RewriteRule ^.*$ https://website.com/profile/? [R=301,L]

Redirect 301 /extra-online-testing/ https://website.com/tests/extra-online-testing/

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

我尝试过其他转换器,但结果相同。

最佳答案

试试这个代码:),让我知道这是否适合你:)

server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        root /var/www/html;
        index index.php index.html index.htm;

        server_name your_domain.com;

        location / {
                # try_files $uri $uri/ =404;
                try_files $uri $uri/ /index.php?q=$uri&$args;
        }

        error_page 404 /404.html;

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/html;
        }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }




          location = /my-courses/ {
          rewrite ^(.*)$ https://website.com/profile/? redirect;
      }

          location / {
          rewrite ^/course-track/* https://website.com/profile/? redirect;
          rewrite ^/course-category/* https://website.com/profile/? redirect;
      }

          location = /courses/ {
          rewrite ^(.*)$ https://website.com/profile/? redirect;
      }

          location /extra-online-testing/ {
          rewrite ^(.*)$ https://website.com/tests/extra-online-testing/ redirect;
      }

          location / {
          rewrite ^/course-category/* https://website.com/profile/? redirect;
      }


}

关于linux - 将 "handmade"htaccess 移至 nginx 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54386031/

相关文章:

c - 调试器如何从代码行中查找表达式

php - 安装 Asterisk 13 + FreePBX 12.0.7

linux - 如何在多个文件中搜索重复的未知字符串

php - 通过 PHP 上传 Wordpress 附件

php - 通过 HTaccess 强制使用 SSL

php - Mod 重写模式问题

linux - 如何在 Linux 6 上保存 Method R Workbench 的许可证 key ?

php - WordPress: fatal error :无法在第 130 行的写入上下文中使用函数返回值

mysql - 我将如何使用 Node.js 作为前端和 Wordpress 作为后端?

php - 在 mod_rewrite 中允许百分比 (%) 符号?