Y
Y
Yaroslav Alekseenko2016-08-22 16:55:48
htaccess
Yaroslav Alekseenko, 2016-08-22 16:55:48

How to set up a tricky redirect in htaccess?

Hello colleagues! Thank you for coming!
Given: there are folders and files in the d.ru domain folder. One of the folders is /folder/subfolder/ and it contains files such as /folder/subfolder/001.txt and the folder /folder/subfolder/texts/abc.txt. There is no /files folder!
The question is how to make all files and folders go in /index.php, except for files and folders that are physically in /folder/subfolder/ but only open as /files/?
Let me clarify so as not to confuse:

  • The virtual name /files/ is the physical folder /folder/subfolder/
  • File /folder/subfolder/001.txt opens /index.php
  • The file /files/001.txt opens the file 001.txt located in /folder/subfolder/
  • File /folder/subfolder/001.txt should not open
  • The /files/texts/abc.txt file opens the abc.txt file located in /folder/subfolder/texts/
  • File /folder/subfolder/texts/001.txt should not open
  • Any other urls/files/folders/links not starting with /files/ open /index.php

Tried to do like this:
RewriteEngine On

RewriteRule ^files/(.*)$ folder/subfolder/$1 [L,QSA]

RewriteCond %{REQUEST_URI} !^files/
RewriteRule ^(.*)$ index.php [L,QSA]

Didn't work very well
. Thank you for your help.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question