User-friendly URL with htaccess pointing

Asked

Viewed 189 times

1

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

www.meudominio.com.br/something/index.php

www.meudominio.com.br/whatever-thing1/index.php

www.meudominio.com.br/whatever-thing2/index.php

www.meudominio.com.br/whatever-thing3/index.php

www.meudominio.com.br/whatever-thing4/index.php

www.meudominio.com.br/whatever-thing5/index.php

Where "anything" is going to change several times, it should work as an Alias for the subfolder where the site is, recognizing really anything that is written there.

If I manually insert in the script the name I want, I realized it works, this way:

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

But I need him to accept everything I put in before the deli, so I tried to do:

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

But it doesn’t work. What am I doing wrong? Is there a more practical way to make it work?

Thanks in advance.

  • You can put some examples of input and desired output?

  • I made an edit on the question and added an example of the URL how it has to work.

  • You must return www.meudominio.com.br/pasta_site/index.php, knowing that "pasta_site" is the real folder where the site is located.

  • I have tried this way, I have not succeeded. There is some piece of code that should be cited before this?

  • I’m quoting only Rewriteengine On, then the code.

  • I can’t see where you’re going wrong, the regex I posted in the comments works, see https://regex101.com/r/y3Y7kr/2

Show 1 more comment

1 answer

1


You can do this with capture denied [^ ].

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

Be working in REGEX101.

Explanation

  • \/?[^\/]* - capture of the "anything" that should end in the /
  • (\/(.*))? - If there is a / captures what comes after it, generating group 2.
  • Good answer. Just one detail: no need to escape the /, nor the $ in the end.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.