Friendly URL with htaccess pointing

1

My site is in a subfolder, I want the path to work regardless of what I enter in the subfolder name, for example:

www.mydomain.com / any-thing / index.php

www.mydomain.com / any-thing1 / index.php

www.mydomain.com / any-thing2 / index.php

www.mydomain.com / any-thing3 / index.php

www.mydomain.com / any-thing4/index.php

www.mydomain.com / any-thing5 / index.php

If I manually enter in the script the name I want, I already noticed that it works, like this:

RewriteRule ^nome-que-eu-quero\/?(.*)$ /pasta_site/$1 [L,QSA]

But I need it to accept everything I insert before the delimiter, I tried to do this:

RewriteRule ^(.*)\/?(.*)$ /pasta_site/$2 [L,QSA]

But it does not work. What am I doing wrong? Is there any more practical way to make it work?

Thank you in advance.

    
asked by anonymous 28.06.2017 / 16:27

1 answer

1

You can do this with the catch denied [^ ] .

RewriteRule ^\/?[^\/]*(\/(.*))?$ /pasta_do_site/$2 [L,QSA]

Be working at REGEX101.

Explanation

  • \/?[^\/]* - capture of "any_ thing" that should end in /
  • (\/(.*))? - If there is a / it captures what comes after it, generating group 2.
30.06.2017 / 15:16