K
K
Kirill Trifonov2017-02-22 14:19:44
HTML
Kirill Trifonov, 2017-02-22 14:19:44

How to remove folder from url using .htaccess?

There is a url like:
example/sites/first/index.html
example/sites/second/index.html
example/sites/third/index.html
and so on...
It is necessary that when entering example/first it shows the page from example/sites/ first/index.html
Likewise with the others.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Viktor Taran, 2017-02-27
@shambler81

RewriteCond %{REQUEST_URI} ^(.*)/dir1/(.*)$ 
# если строка содержит /dir1/ 
RewriteRule ^(.*)$ %1/dir2/%2 [R=301,L] 
#Перенаправить все урлы с начинающиеся с dir1 на dir2 с сохранением дальнейшей структуры URL

I wrote more here.
https://klondike-studio.ru/blog/snipet-for-htaccess/

1
1578, 2018-02-14
@1578

RewriteCond %{DOCUMENT_ROOT}/page/$1 -f
RewriteRule ^(.*)$ page/$1 [L,QSA]
!!!!All links to stranica.php should look like this:
<a href="stranica.php" title ="">page
not like this:
<a href="page/stranica.php" title="">page

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question