0

I'm following this tutorial and there is this file structure:

└── public
   ├── .htaccess
   └── index.php
└── .htaccess

Everything works as expected.

The root .htaccess looks like this:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^$ public/ [L]
    RewriteRule (.*) public/$1 [L]
</IfModule>

I don't know much about .htaccess but I suppose this reroutes the URI to public directory. So every request goes there.

The .htaccess from public directory looks like this:

<IfModule mod_rewrite.c>
    Options -Multiviews
    RewriteEngine On
    RewriteBase /auth/public
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
</IfModule>

Everything above works as expected but I want to enhance it so it works like this:

  1. URL https://www.something.com/anything stays as is
  2. But on the server it is handled like this https://www.something.com/index.php?q=anything (technically https://www.something.com/public/index.php?q=anything)
roadrunner
  • 51
  • 7
  • _"The .htaccess from public directory looks like this"_ - why isn't there any actual rewrite in there? What is the purpose of having RewriteConds, that then don't have any RewriteRule following them? – CBroe Jun 21 '22 at 09:20
  • @CBroe I guess it is an error in the tutorial but doesn't affect the overall result. I'm really not much familiar with the subject. – roadrunner Jun 21 '22 at 09:41
  • 1
    https://stackoverflow.com/questions/18406156/redirect-all-to-index-php-using-htaccess – CBroe Jun 21 '22 at 10:08
  • @CBroe I already found the answer but yours seem to be more elegant. Thank you. – roadrunner Jun 21 '22 at 10:12

1 Answers1

0

Ok, so I found out the answer. I edited the root .htaccess and changed the last line to this: RewriteRule (.*) public/index.php?s=$1 [L]

The whole file now looks like:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^$ public/ [L]
    #RewriteRule (.*) public/$1 [L]
    RewriteRule (.*) public/index.php?q=$1 [L]
</IfModule>

The rewrite rule which rerouted the URIs to the public directory now reroutes the URI to the index's query.

roadrunner
  • 51
  • 7