M
M
MaKS_Ibl42019-08-29 16:13:50
htaccess
MaKS_Ibl4, 2019-08-29 16:13:50

How to properly configure .htaccess for a task?

Comrades, I ask for your help.
What we have:
a slash at the end is required: domain.ru/test -> redirected to test/
the actual string test (maybe two words through a dash, there may be numbers) was given to index.php?page=$1
while js css was loaded from of their folders
, any img/image name request went away getphoto.php?src=image name
any upload/folder/image name request went away as well getphoto.php?folder=&src=
there is also an admin folder, it should work normally.
I ideally want any request other than images or statics to go to index.php?page=
I did this:

RewriteCond %{REQUEST_URI} ^/.*
  RewriteRule ^ajax$ /admin/ajax.php [L]
    RewriteRule ^sitemap.xml$ sitemap.xml [L]
    RewriteRule ^admin/(.*)$ admin/$1 [L]
    RewriteRule ^.*css/(.*)$ css/$1 [L]
    RewriteRule ^.*fonts/(.*)$ fonts/$1 [L]
    RewriteRule ^.*js/(.*)$ js/$1 [L]
    RewriteRule ^.*img/(.*)$  getphoto.php?src=$1 [L]

    RewriteCond %{REQUEST_URI} /$ [NC]
    RewriteRule ^.*img/(.*)(/)$ getphoto.php?src=$1 [L]

    #RewriteCond %{REQUEST_URI} !^/uploads/.*$ [NC]
    #RewriteRule ^(.*)$ getphoto.php?src=$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*[^/])$ $1/ [L,R=301]
    RewriteRule ^(.*)(/)$ index.php?src=$1 [QSA,L]

It seems that in general it works as I want, but I can’t figure out how to intercept requests to the uploads folder

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2019-08-29
@dodo512

RewriteRule ^sitemap.xml$ sitemap.xml [L]
RewriteRule ^admin/(.*)$ admin/$1 [L]
RewriteRule ^uploads/([^/]+)/(.*)$ getphoto.php?folder=$1&src=$2 [L]

RewriteRule (js|css|fonts)/(.*) $1/$2 [L]
RewriteRule img/(.*)$  getphoto.php?src=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)$ /$1/ [L,R=301]

RewriteRule ^(.*)/$ index.php?src=$1 [QSA,L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question