Changing directory structure using .htaccess

I want to move all the files of my website (even including index.php) to a subdirectory (for exp: "abc")

For example BEFORE:

public_html
 index.php
 a.file
 directory
   an.other.file
 ...

AFTER:

public_html
 abc_directory
   index.php
   a.file
   directory
     an.other.file
   ...

I want everything to work as before, but I don't want to do any redirects (visible).

People should enter " http://myexmaplesite.com/directory/an.other.file/ " and serve them through .htaccess apache " http://myexmaplesite.com/abc_directory/directory/an.other.file/ " BUT WITHOUT EXTERNAL TRANSMISSIONS (301.302 etc.)

How could I redirect all requests to a subdirectory using mod_rewrite?

+3
source share
2 answers

mod_rewrite :

RewriteEngine on
RewriteRule !^directory/ directory%{REQUEST_URI} [L]

:

RewriteEngine on
RewriteCond $1 !^directory/
RewriteRule ^/?(.*) directory/$1 [L]

.

+1

-

RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ directory/$1 [L,QSA]
+1

Source: https://habr.com/ru/post/1722877/


All Articles