I’m trying to come up with a regular expression that will indicate if the URL provided is the index page of the site. This means it has to match example.com, example.com/ and example.com/index.php but not example.com/page.php
Here’s a list that I came up with for testing. So many permutations due to www/non-www, http/https, trailing slashes, etc.
It should match these:
http://example.com/index.phphttp://example.com/http://example.comhttp://example.com/index.php?var=Xhttp://example.com/?var=Xhttp://example.com?var=Xhttps://example.com/index.phphttps://example.com/https://example.comhttps://example.com/index.php?var=Xhttps://example.com/?var=Xhttps://example.com?var=Xhttp://www.example.com/index.phphttp://www.example.com/http://www.example.comhttp://www.example.com/index.php?var=Xhttp://www.example.com/?var=Xhttp://www.example.com?var=Xhttps://www.example.com/index.phphttps://www.example.com/https://www.example.comhttps://www.example.com/index.php?var=Xhttps://www.example.com/?var=Xhttps://www.example.com?var=X
It should NOT match these
http://example.com/page.phphttp://example.com/page.php?var=Xhttp://example.com/pagehttp://example.com/page/http://example.com/page/index.phphttp://example.com/page?var=Xhttp://example.com/page/?var=Xhttps://example.com/page.phphttps://example.com/page.php?var=Xhttps://example.com/pagehttps://example.com/page/https://example.com/page/index.phphttps://example.com/page?var=Xhttps://example.com/page/?var=Xhttp://www.example.com/page.phphttp://www.example.com/page.php?var=Xhttp://www.example.com/pagehttp://www.example.com/page/http://www.example.com/page/index.phphttp://www.example.com/page?var=Xhttp://www.example.com/page/?var=Xhttps://www.example.com/page.phphttps://www.example.com/page.php?var=Xhttps://www.example.com/pagehttps://www.example.com/page/https://www.example.com/page/index.phphttps://www.example.com/page?var=Xhttps://www.example.com/page/?var=X
(Are there any other combinations I left out?)
All I’ve come up with so far is:
example.com(/|index.php|)
which is obviously incorrect as it is matching the /page values too.
This works
Note this is a generic regex. To match your flavor you might need to escape.
After running a simple test with
egrephere is the result