I have this link:
http://mysite.com/subdirectory/something/stuff/index.php
What regex would I be able to use that matches only the first slash so that I am able to extract everything behind it using the $1 or $2 variables that represent found items? So that it would return “subdirectory/something/stuff/index.php”.
For example, I thought of using this regex:
(.*)/(.*)
But that keeps repeating for each slash so it will only return the last part (in this case index.php) of the url when I use $2.
The language I’m using it with is apache (?), it’ll go in a .htaccess file.
Thanks in advance!
EDIT:
Ok, so the background on this is that I have some files in the subdirectory linking to other files using links like “/files/test.php”, because those files expect the other directories to be in the root folder, but on my site they aren’t. So I thought of using the htaccess file to redirect those requests to the root folder to the subdirectory so everything works. And replacing all the links is not an option because there are more than a thousand of them.
Try this regular expression (it will redirect to the subdirectory stuff only if the requested file does not exist, so if it exists it won’t loop infinitly) :