I
I
Igor Gusev2019-12-28 06:37:14
Nginx
Igor Gusev, 2019-12-28 06:37:14

How to transfer redirect rules from .htaccess to php nginx handler?

How to correctly transfer .htaccess to nginx php handler? The site itself uses 1C-Bitrix - CMS, but has many new modules and redesigned functions. Almost everything came out to be transferred, except for a few details. Namely:
The link to the news should look like the URL https://smoservice.media/news/?ELEMENT_ID=764766 without index.php (now it is generated automatically and added to the links, for example, in the regular article directory smoservice.media/blog/
Also, the theme color switcher does not work on the https://smoservice.media/telegram/ page (and on the product page), but it works fine on all other
pages.The system also has multi-site from 1C-Bitrix, so all these rules should work and other domains (eg.https://smmbang.ru).

Options -Indexes  
ErrorDocument 404 /404.php  


<IfModule mod_php7.c>  
  php_flag session.use_trans_sid off
  #php_flag default_charset UTF-8
  #php_value display_errors 1
</IfModule>  

<IfModule mod_rewrite.c>  
  Options +FollowSymLinks
  RewriteEngine On

#RewriteMap access txt:/var/www/smoservice/data/www/moonlight.smoservice.media/blacklist_.txt
#RewriteCond ${access:%{REMOTE_ADDR}} deny [NC]
#RewriteRule ^ - [L,F]


#RewriteRule ^pages/([a-z0-9_]+)\.php$ /pages/$1/ [R=301]

#RewriteRule /upload/iblock/fe4/fe4e297043821e32102ef5e25c1ab40f\.jpg /assets/img/social-icons/a-facebook.png

RewriteCond %{REQUEST_URI} !(/$|\.)  
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]  

RewriteCond %{THE_REQUEST} //  
RewriteRule ^.*$ https://smoservice.media/$0 [R=302,L,NE]  

RewriteRule ^fast/index\.php$ /fast [R=301,L]  
RewriteRule ^fast/index\.php/$ /fast [R=301,L]  

RewriteRule ^index\.php$ / [R=301,L]  
RewriteRule ^(.*)/index\.php$ /$1/ [R=301,L]  

RewriteRule ^catalog/([a-z0-9_\-]+)/?$ /$1/ [R=301,L]  


#    RewriteRule ^fast/?$ /fast/item.php [NC,L,QSA]

#    RewriteRule webfonts/(.*)$ https://smoservice.media/assets/vendors/font-awesome/webfonts/$1 [NC,L,QSA]
#    RewriteRule ^img/(.*)$ https://smoservice.media/assets/img/$1 [NC,L,QSA]


      RewriteRule ^fast/([a-z]+)/?$ /fast/item.php?type=$1 [NC,L,QSA]

      RewriteRule ^fast/([a-z]+)/([a-z\-_]+)/?$ /fast/item.php?type=$1&sub=$2 [NC,L,QSA]


      RewriteRule ^subscriptions/([a-z]+)/?$ /subscriptions/service.php?type=$1 [L,QSA]

    RewriteCond %{QUERY_STRING} ^type=(\w+)$
    RewriteRule ^fast/$ /fast/%1/? [L,R=301,QSD]


      RewriteCond %{REQUEST_FILENAME}.php -f


      RewriteRule ^pages/([a-z0-9_\-]+)/?$ /pages/$1.php [NC,L,QSA]


    RewriteCond %{HTTP_HOST} ^www\.smoservice\.media$ [NC]
    RewriteRule (.*) https://smoservice.media/$1 [R=301,L]

    RewriteCond %{HTTP_HOST} ^moonlight\.smoservice\.media$ [NC]
    RewriteRule (.*) https://smoservice.media/$1 [R=301,L]

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-l
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !/bitrix/urlrewrite.php$
  RewriteRule ^(.*)$ /bitrix/urlrewrite.php [L]
  RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]



</IfModule>  

<IfModule mod_dir.c>  
  DirectoryIndex index.php index.html
</IfModule>  

<IfModule mod_headers.c>  
    Header set X-Frame-Options SAMEORIGIN
    Header set X-Content-Type-Options nosniff
</IfModule>  

<IfModule mod_mime.c>  
    AddType font/opentype .otf
    AddType application/x-font-woff .woff
    AddType application/x-font-woff2 .woff2
    AddType application/x-font-ttf .ttf
    AddType application/vnd.ms-fontobject .eot
    AddType image/svg+xml .svg
</IfModule>  


<IfModule mod_expires.c>  
  ExpiresActive on
  ExpiresByType image/jpeg "access plus 3 day"
  ExpiresByType image/gif "access plus 3 day"
  ExpiresByType image/png "access plus 3 day"
  ExpiresByType text/css "access plus 3 day"
  ExpiresByType application/javascript "access plus 3 day"
  ExpiresByType application/x-font-woff "access plus 1 year"
  ExpiresByType application/x-font-woff2 "access plus 1 year"
</IfModule>  


<ifModule mod_gzip.c>  
mod_gzip_on Yes  
mod_gzip_dechunk Yes  
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$  
mod_gzip_item_include handler ^cgi-script$  
mod_gzip_item_include mime ^text/.*  
mod_gzip_item_include mime ^application/x-javascript.*  
mod_gzip_item_exclude mime ^image/.*  
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*  
</ifModule>

Question. What needs to be added in order to solve the problem of adding index.php to the internal links of the elements in the first place + their further redirect to the page with "/" when opened by the user in the browser.

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