I want a fundamental redirect inside a .htacess file, from the directory Hyperlink to personal files:

RewriteRule ^(.*)/mydirectory/(.*)$ myfile.php?q=$2

It's not working. The issue is I can not get results unless of course I actually do:

RewriteRule (.*)mydirectory(.*)$ myfile.php?q=$2

by which situation the taken string ($2) is "mydirectory" (?!), not to mention the rule would affect any URL that contains "mydirectory" like a substring, even when it isn't between slashes, that is not good.

The exam URL is:

http://localhost/base/mydirectory/some-other-string

Things I expect is:

http://localhost/base/myfile.php?q=some-other-string"

Things I get using the first rule is certainly not (rule doesn't apply/no longer working), and "myfile.php?q=base/mydirectory" using the second rule, correspondingly.

Exactly the same happens basically use RewriteCond: the moment I add the damned forward slashes, the rule doesn't apply any longer. I even steered clear of the forward slashes, although you shouldn't have for your, with no success.

I am not really a mod_rewrite expert, but I am no stranger into it. IMO, the very first rule should work, however it does not. I am most likely doing something horribly wrong, but I am too near to view it.

Please have a look, it's driving me nuts.

Thank you.

Slashes have particular meanings in regular expressions you have to escape them:

RewriteRule ^(.*)\/mydirectory\/(.*)$ myfile.php?q=$2