AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题

问题[rewrite](server)

Martin Hope
Rebecca Hubbard
Asked: 2023-01-19 06:17:41 +0800 CST

RegEx for 301 重定向以更改路径并删除字符串

  • 5

我正在寻找 RegEX 重定向规则以将图像文件位置重定向到新位置,同时还删除部分原始 url,即图像名称

旧网址:

/components/com_mijoshop/opencart/image/cache/catalog/ecom2/GM815-365x365.jpg

新网址:

/wp-content/uploads/nc/catalog/ecom2/GM815.jpg

所以我需要更改目录路径并删除 url 的“-365x365”部分。

我可以使用以下内容删除图像名称的一部分,但不确定如何更改路径:

/(?'path'.*)-365x365.jpg  /[path].jpg
rewrite
  • 1 个回答
  • 31 Views
Martin Hope
Isaac Palacio
Asked: 2022-04-14 07:23:45 +0800 CST

Nginx Redict 不修改 url

  • 0

我想从一个域重定向到另一个域,但只从一个页面。

示例: https ://domainA.com/site/page到https://domainB.com/site/page

在nginx中我放了:

location /site {
         rewrite ^/site/page https://domainB.com/site/page break;
}

它有效,它做了rediction,但它改变了url,我希望url始终是https://domainA.com/site/page

我该怎么做才能使网址不变?

谢谢你!

rewrite nginx
  • 1 个回答
  • 39 Views
Martin Hope
halloleo
Asked: 2022-04-01 20:08:03 +0800 CST

在 Apache 上,如何仅针对对特定子域的请求关闭 DirectorySlash?

  • 1

由 Apache 提供服务我希望在我的一个子域站点(例如sub.mydomain.com)上,没有尾部斜杠的 URL 直接(没有外部重定向)指向底层文件夹中的索引文件。子域请求在内部重定向到子文件夹。所有其他 URL 应该以正常的 Apache 方式工作,外部重定向到斜线版本。

所有指令都必须放在我的 .htaccess 文件中。为此,我计划执行以下操作:

  1. 关闭DirectorySlash请求sub.mydomain.com/...
  2. sub.mydomain.com/…将请求重写为/sub/...
  3. 重写无斜杠目录 URL /sub/...以获取index.html底层目录内部

我对如何执行 2. 和 3. 有一个好主意,但是我如何才能DirectorySlash off 仅针对请求sub.mydomain.com而不是www.mydomain.comor发出请求other.mydomain.com?

rewrite .htaccess mod-rewrite apache-2.4
  • 1 个回答
  • 52 Views
Martin Hope
Totoro
Asked: 2022-03-17 12:32:11 +0800 CST

试图让 Apache 服务于 webp 而不是 png/jpg(来自 prestashop 的 /img 文件夹)

  • 1

第一次在这里发帖,所以我希望我做得很好。

我从我的 prestashop public_html 文件夹开始将所有 png/jpg 转换为 webp,并向 .htaccess 添加了重写规则,以便提供 webp 而不是 png/jpg。

我的重写基于已经存在的 prestashop 重写。我在哪里:
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]
我最终做了:

RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.webp [L]
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.webp$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.webp [L]
RewriteRule ^([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]

哪个有效:我得到了提供 webp 图像的 jpg URL,到目前为止一切都很好(我知道仍然需要实现

#RewriteCond %{HTTP_ACCEPT} image/webp
#RewriteCond %{DOCUMENT_ROOT}/$1.webp -f

并且尝试弄清楚我是否应该离开[L]或做[L,T=image/webp]或做[T=image/webp,E=REQUEST_image],这就是为什么我正在阅读与 apache 相关的文档并在网络上爬取关于重写相关主题的内容,这确实是巨大的。

好的,回到主题,我发现我缺少对 prestashop 存储在 public_html/img 文件夹中的图像的 webp 重写。

然后我尝试了以下(以及其他变体):

RewriteRule ^/img/(.+)\.jpe?g$ /img/$1.webp [L]
RewriteRule ^/img/(.+)\.png$ /img/$1.webp [L]

^--- 不好...仍然从 img 目录提供 jpg/png 类型的图像(仔细检查 MIME 类型)。

注意:

  1. 每次我更改 .htaccess 并尝试解决方案时,我都会清除 prestashop 缓存,以防万一(尽管知道每次请求都会读取 .htaccess)。
  2. 存在 img 文件夹中 jpg/png 对应的 webp 图片。
  3. 图像文件 perms 在 img 文件夹中是正确的,实际上在 public_html 下的所有东西中都是正确的
  4. 在 prestashop 的 img 文件夹中,还有另一个 .htaccess,它限制了可以从此文件夹提供的文件类型,我已经添加了 webp,以防万一有人问。

更新:根据 MrWhite 的要求,添加 img 文件夹的 .htaccess

<IfModule mod_php5.c>
    php_flag engine off
</IfModule>

# Apache 2.2
<IfModule !mod_authz_core.c>
    Order deny,allow
    Deny from all
    <Files ~ "(?i)^.*\.(webp|jpg|jpeg|gif|png|bmp|tiff|svg|pdf|mov|mpeg|mp4|avi|mpg|wma|flv|webm|ico)$">
        Allow from all
    </Files>
</IfModule>

# Apache 2.4
<IfModule mod_authz_core.c>
    Require all denied
    <Files ~ "(?i)^.*\.(webp|jpg|jpeg|gif|png|bmp|tiff|svg|pdf|mov|mpeg|mp4|avi|mpg|wma|flv|webm|ico)$">
        Require all granted
    </Files>
</IfModule>

请问你们能帮我吗?

rewrite .htaccess extension mod-rewrite images
  • 1 个回答
  • 536 Views
Martin Hope
dinastar66
Asked: 2022-03-09 03:59:43 +0800 CST

nginx 反向代理 IP_adr/1881 到 localhost:1881 proxy_pass

  • 0

我已经阅读了这篇文章,并尝试了很多事情,但我遇到了重写正则表达式的问题。 这里

我有许多 node.js 进程作为后端,总是使用不同的端口来访问。

在同一台服务器上使用 Nginx 反向代理,我想传递例如:https://my-site/1881到http://127.0.0.1:1881proxy_pass。

我可以从中得到 1881,my-site/1881但我总是在最后127.0.0.1:1881/1881。或者 Nginx 错误。我不确切知道如何删除 /1881 rewrite。

我试过了:

location ~ ^/(?<port>\d\d\d\d)$ {            #Ok

        rewrite "^/[0-9]{4}(.*)$" $1 break;  #try and retry here
        proxy_pass http://127.0.0.1:$port;   #Ok
}

感谢您的帮助,祝您有美好的一天

rewrite port nginx regex
  • 1 个回答
  • 87 Views
Martin Hope
pok4
Asked: 2022-03-02 12:58:18 +0800 CST

将规则从 apache 重写为 nginx

  • 0

我对此有疑问...我正在使用免费托管为我自己的 cms 的未来买家提供演示。

主机是hubuhost.com,他们支持最新版本的php 8.1。问题是它们在 nginx 上并且不支持我的 apache 的 htaccess 规则。

我的配置是:

<IfModule mod_negotiation.c>
#Important rules for our system
Options -Multiviews -Indexes +FollowSymLinks
</IfModule>

#app.php instead of index.php
<IfModule mod_dir.c>
DirectoryIndex core.php index.php index.html
</IfModule>

#If 404 - redirect to 404 page
ErrorDocument 404 /404/index.php

<IfModule mod_rewrite.c>
#ModRewrite ON
RewriteEngine on 

#News SEO Urls
RewriteRule  ^topic_(.+?)$ core.php?id=$1

#Router
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ core.php [QSA,L]
 
#remove end trailing slash from urls
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /(.*)/$
RewriteRule ^ /%1 [R=301,L]
</IfModule>

#Block ENV access
<IfModule mod_version.c>
<Files "config.env">
   Order allow,deny
    Deny from all
</Files>
</IfModule>

有人可以将其转换为 nginx 吗?

我尝试了一些规则,但没有成功。我不知道该怎么办...来自管理面板的演示图片:https ://i.ibb.co/gwZStXN/image.png

rewrite .htaccess redirect nginx rules
  • 1 个回答
  • 404 Views
Martin Hope
user515576
Asked: 2022-03-02 12:50:11 +0800 CST

Nginx 入口 - 转义字符

  • 0

我有以下通过 nodePort 32100 公开的入口配置。当我调用(卷曲)包含括号的 URL [1] 时,我收到 HTTP 500 错误。但是当我调用不包含括号的 URL [2] 时,请求通过 NGINX 入口控制器(v0.35.0)成功传递。

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/proxy-body-size: 0m
    name: test1-app-ingress
  namespace: test1
spec:
  rules:
  - host: ing1.example.com
    http:
      paths:
      - backend:
          serviceName: test1-app-1-ingress
          servicePort: 80
        path: /test1
  - host: ing2.example.com
    http:
      paths:
      - backend:
          serviceName: test1-app-2-ingress
          servicePort: 80
        path: /test1

[1]

curl  "http://ing1.example.com:32100/test1/test1.json/Streams(Type_4000000)" -X POST --data-binary @25kfile 
* About to connect() to ing1.example.com port 32100 (#0)
*   Trying 10.10.10.30...
* Connected to ing1.example.com (10.10.10.30) port 32100 (#0)
> POST /test1/test1.json/Streams(Type_4000000) HTTP/1.1
> User-Agent: curl/7.29.0
> Host: ing1.example.com:32100
> Accept: */*
> Content-Length: 25000
> Content-Type: application/x-www-form-urlencoded
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
< HTTP/1.1 500 Internal Server Error
< Server: nginx
< Date: Tue, 01 Mar 2022 20:08:07 GMT

应用程序日志:

10.113.4.0 - - [01/Mar/2022:20:08:07 +0000] "POST /test1/test1.json/Streams(Type_4000000) HTTP/1.0" 500 528 "-" "curl/7.29.0" 25283 0.004 [test1-test1-app-1-ingress-80] [] 10.113.4.157:80 528 0.003 500 4b3fd4d41fb8a2d26691bd2da78f24b

[2]

curl  "http://ing1.example.com:32100/test1/test1.json/StreamsType_4000000" -X POST --data-binary @25kfile 
* About to connect() to ing1.example.com port 32100 (#0)
*   Trying 10.10.10.30...
* Connected to ing1.example.com (10.10.10.30) port 32100 (#0)
> POST /test1/test1.json/StreamsType_4000000HTTP/1.1
> User-Agent: curl/7.29.0
> Host: ing1.example.com:32100
> Accept: */*
> Content-Length: 25000
> Content-Type: application/x-www-form-urlencoded
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
< HTTP/1.1 200 OK
< Server: nginx
< Date: Tue, 01 Mar 2022 20:09:59 GMT

应用程序日志:

172.28.120.65 - - [01/Mar/2022:20:09:59 +0000] "POST /test1/test1.json/StreamsType_4000000 HTTP/1.0" 200 0 "-" "curl/7.29.0" 25281 0.003 [test1-test1-app-1-ingress-80] [] 10.113.4.157:80 0 0.003 200 133bbb4f7149d31e75cf78158566efee

这是 NGINX IC 的问题吗?我应该转义入口配置上的任何字符,比如括号吗?

rewrite nginx kubernetes nginx-ingress
  • 1 个回答
  • 142 Views
Martin Hope
Christian
Asked: 2022-02-18 01:41:16 +0800 CST

nginx - 尝试使用内部变量重定向路径失败

  • 0

我想将请求重定向到一个文件

/path/to/file/content?path=file.pdf

至

/new/path/to/file/file.pdf

在同一个域下。

我尝试了简单的重写规则或像这样。

location ~ ^/path/to/file/content?path=(.*) {
   return 301 /new/path/to/file/$1;
}

不幸的是,nginx 不理解这个变量。我究竟做错了什么?请问有人给我小费吗?不幸的是,我对 reqex 了解不多。非常感谢!

rewrite nginx
  • 1 个回答
  • 89 Views
Martin Hope
Adam Larsson
Asked: 2022-01-31 06:23:31 +0800 CST

Apache http 到 https 没有任何地址?

  • 1

正常的 http 到 https 重写可能如下所示:

RewriteEngine On
# RewriteCond %{HTTP_HOST} !^example.com$
# RewriteRule /.* https://example.com/ [R]

但是此代码将站点指定为“example.com”

无论如何要进行“全局”重写,因此无论是否有人打开example.com、broken.example.com 甚至example.Lom(只要 DNS 指向服务器),它都会简单地放一个 https在上面?

适用于拥有多个域名的服务器。

能够在任何地方使用相同的代码会很棒..

rewrite mod-rewrite rewritecond
  • 1 个回答
  • 42 Views
Martin Hope
TravelWhere
Asked: 2022-01-16 18:59:25 +0800 CST

如果通过浏览器直接访问图像文件,如何重定向用户?[nginx]

  • 0

如果用户尝试仅在浏览器中直接访问图像文件,我该如何重定向?我想保留嵌入图像的能力<img src="...">。如何从重定向

https://img.example.com/c/600x1200_90_webp/img-master/img/2022/01/03/08/04/54/95259215_p0_master1200.jpg

至

https://example.com/detail?id=95259215

这是我的 nginx 配置文件

location ~ "^/c/600x1200_90_webp/img-master/img/\d+/\d+/\d+/\d+/\d+/\d+/(?<filename>.+\.(jpg|png|webp))$" {
    return 301 https://example.com/detail?id=$filename;
}

代码不起作用,因为它会起作用,https://example.com/detail?id=95259215_p0_master1200.jpg但我需要它在文件名的最后一位数字之后修剪字符串,所以在这种情况下 trim off _p0_master1200.jpg。如果用户通过浏览器访问它,我也不知道如何制作它。

rewrite redirect nginx
  • 1 个回答
  • 264 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve