How do I direct every request to a subfolder? (HTACCESS)

Asked

Viewed 538 times

3

I have tried several tutorials and none worked beyond the index.php.

Use the LOCALHOST and I intend that all requisition, of any kind, example:

localhost:8080/teste.php
localhost:8080/imagens/algo.jpg
localhost:8080/teste2.php?querystring=ok

Be redirected to the folder inside the WWW thus: /wamp/www/PASTA/(os arquivos das URLs estão aqui).

But I need the redirect if it could be invisible, it would be perfect.

What I tried and just redirected to INDEX.PHP of PASTA, but the other files were giving error 404.:

RewriteEngine on
RewriteCond %{HTTP_HOST} localhost [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /pasta/$1 [L]
  • Welcome to the stackoverflow.

  • Thank you very much. :)

1 answer

2


Here’s what I used to redirect to a subdirectory. This happens invisibly and even allows requests that match an existing file:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?site.com$
RewriteCond %{REQUEST_URI} !^/subdir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subdir/$1
RewriteCond %{HTTP_HOST} ^(www.)?site.com$
RewriteRule ^(/)?$ subdir/index.php [L]

Browser other questions tagged

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