mod 重写 - 允许句号

发布于 2024-12-11 17:09:00 字数 401 浏览 0 评论 0原文

我需要一个允许句号的重写规则。我怎么能允许这样呢?我想要的是为了 shop/domain/www.test.com 成为 shop/domain/controller.php?param1=www.test.com

我原来的规则如下:

RewriteRule ^shop/domain/([^/.]+)/? $ shop/stock/controller.php?param1=$1 [NC]

这有效,但前提是我删除句号。

我还尝试了以下操作:

RewriteRule ^shop/domain/([^/]+)/?$ shop/domain/controller.php?param1=$1 [NC]

这允许句号,但随后有controller.php参数应为 www.test.com。

I need a rewrite rule that allows full stops. How can I allow for this? What I want is for
shop/domain/www.test.com to become shop/domain/controller.php?param1=www.test.com

The original rule I have is below:

RewriteRule ^shop/domain/([^/.]+)/?$ shop/stock/controller.php?param1=$1 [NC]

This works but only if I remove the full stop.

I have also tried the following:

RewriteRule ^shop/domain/([^/]+)/?$ shop/domain/controller.php?param1=$1 [NC]

This allows the full stop but then has controller.php is the parameter when it should be www.test.com.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

記憶穿過時間隧道 2024-12-18 17:09:00

如果所有域都以“www.”开头,您可以执行此操作。

RewriteRule ^shop/domain/www\.([^/]+)/?$ shop/domain/controller.php?param1=$1 [NC,L]

您的规则的问题是,它也与 controller.php 匹配,就好像它是一个域一样。您可以添加以下两个重写条件来防止这种情况:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^shop/domain/([^/]+)/?$ shop/domain/controller.php?param1=$1 [NC,L]

!-d 表示不是现有目录,!-f 表示不是现有文件(例如 controller.txt)。 php)。

If all domains begin with "www.", you could do this

RewriteRule ^shop/domain/www\.([^/]+)/?$ shop/domain/controller.php?param1=$1 [NC,L]

The problem with your rule is, that it also matches controller.php as if it were a domain. You can add the following two rewrite conditions to prevent this:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^shop/domain/([^/]+)/?$ shop/domain/controller.php?param1=$1 [NC,L]

!-d means not an existing directory, !-f means not an exisiting file (e.g. controller.php).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文