Remove the folder name from the url

There is a website and the page folder contains the main pages

Www.site.com/page/stranica.php

Creating .htaccess

RewriteRule ^page/(.+)$ http://www.site.com/$1 [R=301,L]

I upload to the root and nothing happens. Where did I go wrong, please tell me?

Author: Nicolas Chabanovsky, 2015-09-18

2 answers

You need to escape the slash in order for the regular expression to work

RewriteEngine On
RewriteRule ^page\/(.+)$ http://www.site.com/$1 [R=301,L]

UPD

RewriteEngine On - enables the processing of forwarding rules in .htaccess.

UPD2

Created such a construction

<IfModule mod_rewrite.c>

# включаем обработку переадресаций
 RewriteEngine On

# проверка переменной в параметрах запроса для отмены зацикливание переадресации
 RewriteCond %{QUERY_STRING} !stopredirect=STOPREDIRECT
# проверка, что файл к которому обратились существует на сервере
 RewriteCond %{REQUEST_FILENAME} -f
# проверка, что обратились к файлу в папке page
 RewriteCond %{REQUEST_URI} ^\/page\/(.+)$
# 301 редирект на файл в корне сайта
 RewriteRule .* /%1 [R=301,L]

# так как файла в корне сайта нет, нужно открыть файл из папки page не меняя url
# проверка, что обратились к файлу в корне сайта
 RewriteCond %{REQUEST_URI} ^\/([^\/]+)$
# проверка, что такой файл есть в папке page
 RewriteCond %{DOCUMENT_ROOT}page%{REQUEST_URI} -f
# открываем файл из папки page (дописывая параметр stopredirect в запрос для отмены зацикливания)
 RewriteRule .* /page%{REQUEST_URI}?stopredirect=STOPREDIRECT&%{QUERY_STRING} [L]

</IfModule>
  1. It works when accessing actual files located in the page folder. In this case, page/ (301 redirect) is removed from the url in the browser's address bar. If there is no file in the page folder, change the url in the address bar the browser does not occur, a 404 error is output.
  2. When accessing a file in the root of the site with the name of a real file in the folder page, the file is launched from the folder page.
 2
Author: Visman, 2015-09-18 15:04:07
RewriteCond  %{DOCUMENT_ROOT}/page/$1 -f

RewriteRule ^(.*)$ page/$1 [L,QSA]

All links to stranica.php they should look like this:

<а href="stranica.php" title="">страница 

And not so:

<а href="page/stranica.php" title="">страница
 0
Author: Кирилл Корсак, 2018-02-14 17:33:45