匹配 OpenCart url 格式的正则表达式

发布于 2024-12-25 07:23:56 字数 409 浏览 6 评论 0原文

我需要一个正则表达式来匹配此 URL 以启用 URL 重写。

http://www.somewhere.com/index.php?route=common/home

这是一个 OpenCart 网站。

更新:

我正在尝试使用正则表达式在 IIS7 上执行 URL 重写。 URL 的第一部分不需要精确的域名匹配,但我需要获取结果 URL,如下所示

http://www.somewhere.com/common/home

I need a regular expression to match this URL to enable URL rewriting.

http://www.somewhere.com/index.php?route=common/home

This is an OpenCart website.

UPDATE:

I am trying to use the regular expression to perform URL Rewriting on IIS7. The first part of the URL doesn't need exact domain name matching but I need the to get a resulting URL as follows

http://www.somewhere.com/common/home

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

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

发布评论

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

评论(2

等往事风中吹 2025-01-01 07:23:56

您没有指定执行此操作所用的语言(提示:并非所有正则表达式实现都具有相同的规则),因此我在 python 中解决它:

>>> import re
>>> pattern = '([^/]+)//([^/]+)/index\.php\?route=([^ ]+)'
>>> repl = '\\1//\\2/\\3'
>>> url = 'http://www.somewhere.com/index.php?route=common/home'
>>> re.sub(pattern, repl, url)
'http://www.somewhere.com/common/home'

you didn't specify the language in which you're doing this (protip: not all regexp implementations have the same rules) so I'm solving it in python:

>>> import re
>>> pattern = '([^/]+)//([^/]+)/index\.php\?route=([^ ]+)'
>>> repl = '\\1//\\2/\\3'
>>> url = 'http://www.somewhere.com/index.php?route=common/home'
>>> re.sub(pattern, repl, url)
'http://www.somewhere.com/common/home'
疯了 2025-01-01 07:23:56

url 重写获取您的域名后面的 url 和初始的 / 并使用 route 参数通过 GET 将其传递给 index.php,因此

http://www.yourdomain.com/common/home

变为

http://www.yourdomain.com/index.php?_route_=common/home

_route_ 被 url 重写控制器用来计算出正确的路径要使用的页面/路线。请注意,要反转该过程(创建 url),您只需在设置页面上启用 url 重写即可启用它们

也就是说,默认情况下 url 重写仅适用于产品、类别、制造商和信息页面 - 所以您不会能够对公共/家乡路线执行此操作。然而,有一些模块可以做到这一点,甚至允许您进一步自定义 url,例如我的 Uber SEO 模块,尽管这改变的不仅仅是基本 url

The url rewrite gets the url after your domain and the initial / and passes it to index.php via GET using the route parameter, so

http://www.yourdomain.com/common/home

becomes

http://www.yourdomain.com/index.php?_route_=common/home

The _route_ is used by the url rewriting controller to work out the correct page/route to use. Note that to reverse the process (create the urls) You just need to enable the url rewriting on the settings page to enable them

That said, url rewriting by default only works for products, categories, manufacturers and information pages - so you won't be able to do that for the common/home route. There are modules out there however that will do that, and even allow you to customise the urls further such as my Uber SEO module, though that changes more than just basic urls

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