I have 3 url for example
- Homepage: www.example.com/
- Admin: www.example.com/wp-admin
- Products: www.example.com/products
3rd url could be any url after main domain like so: www.example.com/something
What i want is to redirect url if only the url is something after main domain but cannot be /wp-admin or main domain www.example.com.
Only redirect if www.example.com/something
Conclusion: Home page and /wp-admin intact, otherwise redirect. Hoping to solve it with regex if possible as any other access to cPanel or source code is not possible. Thank you 🙏
I’ve attempted countless regex but couldn’t do it.
2
Answers
You could use the following regex :
^www.example.com(/?|(/wp-admin))$
which match the domain followed by either nothing or /wp-admin.
It will match
All of the others URLs would not match the regex, so you can juste it as a condition and reverse it if needed.
You can use the following pattern.
This will match these,
And, not these,
Essentially, the
(?!wp-admin)
is a look-ahead, which is asserting that the text at that point, will not equal "wp-admin".Here is the Wikipedia article, outlining regular expression assertions.
Wikipedia – Regular expression – Assertions.