Htaccess redirects from root to subfolder and then disguises the url?

Two things:

First of all . I have version 2 of a website located in a folder named v2, and I want to redirect any traffic that is NOT a child of the v2 folder to www.example.com/v2

The old site, located at the root, was created on iWeb and has many subfolders and subfolders.

So:

www.example.com/v2 = New site

www.example.com/Page.html

www.example.com/category/Page.html

ww.example.com/category/subcategory/Page.html = All typical examples of what I need to redirect.

Secondly, and I don’t know if this is possible, I want to hide / v2 / in the URL so that visitors just see www.example.com/page, although they are actually on www.example.com/v2 / page

Links are hardcoded to the v2 folder, for example, <a href="v2 / contact.html ">

Any help MOST appreciated. I spent hours trying to figure this out, but I'm just learning about htaccess and regular expressions, and I'm completely confused.

Many thanks!

+3
source share
2 answers
RewriteCond %{REQUEST_URI} !^v2/
RewriteRule ^(.*)$ v2/$1 [L] 
+3
source

rewrite everything by including v2 in it.

RewriteRule ^(.*)$ v2/$1 [L] 

www.example.com/Page.html should now be processed as /v2/Page.html

You should not include v2 / in the URL sent to the user.

then it will become v2 / v2 /

+1
source

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


All Articles