Swap site root directory with htaccess

Asked

Viewed 32 times

-1

How to make sure that when a person accesses the site, the . htaccess recognizes that the site is on /site instead of /, /website where it will contain all the files of the site. And when accessing the URL should open www.site.dev/ instead of www.site.dev/site

Image the folders:

inserir a descrição da imagem aqui

Code I’m using:

<IfModule mod_rewrite.c>
   RewriteEngine On
   Options All -Indexes

   # ROUTER WWW Redirect.
   # RewriteCond %{HTTP_HOST} !^www\. [NC]
   # RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

   # ROUTER HTTPS Redirect
   RewriteCond %{HTTP:X-Forwarded-Proto} !https
   RewriteCond %{HTTPS} off
   RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

   # ROUTER URL Rewrite
   RewriteCond %{SCRIPT_FILENAME} !-f
   RewriteCond %{SCRIPT_FILENAME} !-d

   RewriteRule ^(.*)$ site/$1 [L]
</IfModule>

I’ve tried to:

RewriteRule (?!^site/)^(.*)$ /site/$1 [L,NC]

RewriteCond %{REQUEST_URI} !folder/
RewriteRule (.*) /site/$1 [L]

Thank you.

1 answer

0

Maybe you need this:

Options +FollowSymLinks -MultiViews # Turn mod_rewrite on

RewriteEngine On RewriteBase /
RewriteCond %{DOCUMENT_ROOT}/site/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/site/$1 -d [OR]
RewriteCond %{DOCUMENT_ROOT}/site/$1 -l
RewriteRule (?!^site/)^(.*)$ /site/$1 [R=302,L,NC] 

After checking that it is working, change the R=302 for R=301 in the last row.

Reference: https://stackoverflow.com/a/16513060/7970301

  • Lucius, I had succeeded that way RewriteRule ^ - [L] RewriteRule ^/?$ site/ [NC,L,QSA] can you tell me if it’s a correct format to use?

  • 1

    It would be interesting to put the 301 code to "warn" the search engines that it really is something permanent

Browser other questions tagged

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