Redirect with . htaccess, from www folder to public project folder

Asked

Viewed 664 times

-1

I need to set up a redirect through . htaccess.

My "DOCUMENT_ROOT" (using Apache and PHP) is set to "www", which is the root of the project, but index.php is in the "public" folder".

I don’t know if it has to do with versions, but the guy’s tutorial says the following:

In the www folder, a . htaccess with the contents below:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /public/index.php?url=$1 [QSA, L]

And in the public folder, a . htaccess with the contents below:

Option -Indexes

However, like many tutorials, it did not work!! Which leads me to think that it is something to do with version, because in the presentation it works!

My project I’m simulating locally, so my url is "http://localhost/".

That should be redirected to "http://localhost/public/index.php" and should still continue to show "http://localhost/" in the browser.

I found several "solutions", both here and abroad, but none worked.

1 answer

0

In your example, Rewriterule is correct, if it does not find the file in the current directory, it will direct to index.php and the url will receive all the content of the original request.

HOWEVER, you say that . htaccess must be running on your localhost, you failed to inform: -Is your server (APACHE) enabled? -Are you also prepared to read the . htaccess configuration files in the directories where you are placing them? -There is no file in the www directory, because if there is the requested file it uses the file, and not the rewritten file....

  • I forgot to comment!! Mas.. I believe it refers to the line: Loadmodule rewrite_module modules/mod_rewrite.so Well, I had already uncommented it, and... it didn’t work!!! In the case of the www directory, it is my root directory, where the redirect . htaccess.

  • your mod_rewrite is working, once you have uncommented you need to restart apache to work.....

  • https://httpd.apache.org/docs/2.2/pt-br/howto/htaccess.html

  • gives a read on this howto apache, because it will help you if you need to enable the file, because it may be configured with another name, or not configured.....

  • I’ll read, but.. I did the procedure as it is, ie... I enabled the line and restarted apache.. I still cleaned cache, updated the page.. and.... nothing!!! strange!!

Browser other questions tagged

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