Advanced Regex Question for URL Matching
-
Hi,
I have a website that has numerous 'versions' of the homepage (I know this is an issue with duplicate content - that's separate to this and we are working on that).
I need to write a regular expression that matches all the following versions of the homepage:
- http://www.mysite.com
- http://www.mysite.com/
- http://www.mysite.com/default.aspx
- http://www.mysite.com/Default.aspx
- https://www.mysite.com
- https://www.mysite.com/
- https://www.mysite.com/default.aspx
- https://www.mysite.com/Default.aspx
At the same time, it needs to **not **match other pages on the site, such as http://www.mysite.com/page1.
How would I write this?
Thanks,
-
I'm not sure what context you're using this in but this should do the trick (works with PCRE)
^http://www.mysite.com(?:/|)(?:[D,d]efault.aspx|)$
-
I think you should look into the DirectoryIndex directive instead.
-
Hi,
Thanks for the response. It's for Google Tag Manager.
In the end we had to set it up thus:
(https?://www.mysite.com/default.aspx)|(https?://www.mysite.com/?$)
GTM has an option to let you ignore case in the regex. For some reason, it didn't work if we swapped the two URLs either side of the pipe around.
Thanks!