我正在尝试提出一个正则表达式,该表达式将指示提供的 url 是否是网站的索引页面。这意味着它必须匹配 domain.com、domain.com/ 和 domain.com/index.php 而不是 domain.com/page.php
这是我想出的用于测试的列表。由于 www/nonwww、http/https、斜杠等导致的排列如此之多。
它应该匹配这些:
- http://site.com/index.php
- http://site.com/
- http://site.com
- http://site.com/index.php?var=X
- http://site.com/?var=X
- http://site.com?var=X
- https://site.com/index.php
- https://site.com/
- https://site.com
- https://site.com/index.php?var=X
- https://site.com/?var=X
- https://site.com?var=X
- http://www.site.com/index.php
- http://www.site.com/
- http://www.site.com
- http://www.site.com/index.php?var=X
- http://www.site.com/?var=X
- http://www.site.com?var=X
- https://www.site.com/index.php
- https://www.site.com/
- https://www.site.com
- https://www.site.com/index.php?var=X
- https://www.site.com/?var=X
- https://www.site.com?var=X
它不应该匹配这些
- http://site.com/page.php
- http://site.com/page.php?var=X
- http://site.com/page
- http://site.com/page/
- http://site.com/page/index.php
- http://site.com/page?var=X
- http://site.com/page/?var=X
- https://site.com/page.php
- https://site.com/page.php?var=X
- https://site.com/page
- https://site.com/page/
- https://site.com/page/index.php
- https://site.com/page?var=X
- https://site.com/page/?var=X
- http://www.site.com/page.php
- http://www.site.com/page.php?var=X
- http://www.site.com/page
- http://www.site.com/page/
- http://www.site.com/page/index.php
- http://www.site.com/page?var=X
- http://www.site.com/page/?var=X
- https://www.site.com/page.php
- https://www.site.com/page.php?var=X
- https://www.site.com/page
- https://www.site.com/page/
- https://www.site.com/page/index.php
- https://www.site.com/page?var=X
- https://www.site.com/page/?var=X
(还有其他我遗漏的组合吗??)
到目前为止,我想出的是:
site.com(/|index.php|)
这显然是不正确的,因为它也匹配 /page 值。