I want to rewrite
http://site.tld/fake1/fake2/page?options
to
http://site.tld/page?options
basically getting everything is after the last slash, so without knowing in advance any fake foder names
I want to rewrite
http://site.tld/fake1/fake2/page?options
to
http://site.tld/page?options
basically getting everything is after the last slash, so without knowing in advance any fake foder names
2
Answers
You can use capturing groups and replace as follows.
Regex:
^(.*.tld/).*?([^/]*$)$
Explanation:
^(.*.tld/)
matches beginning part till domain name..*?
matches thefake1/fake2/
([^/]*$)$
matches the later part of URL.Replacement to do: Replace with back-referencing groups
12
.Regex101 Demo
First, make sure you’ve enabled mod_rewrite and allowed htaccess in Apache configuration file.
Then, put this code in your htaccess