Home > Blockchain >  htaccess rewriterule to subdirectory without 301
htaccess rewriterule to subdirectory without 301

Time:09-17

I have a question about a RewriteRule with .htaccess without 301. Below my directory structure:

 -root
 --public
 --app

In the root directory I have a directory public and app. In the directory public I have an index.php file.

In the root directory I have a .htaccess file and I want all traffic to got to the index.php file in the directory public.

What I have tried:

RewriteEngine On

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

The rewrite does nothing and I see the index from the directory

Who can help me?

CodePudding user response:

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

You need to remove the 3rd condition that checks if the requested URL-path starts /public/. Presumably, you are making a request for something like /foo, so this condition will prevent the rule from doing anything.

  • Related