Skip to content

Instantly share code, notes, and snippets.

@gartes
Created February 15, 2022 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gartes/7ff41ca92bc513f2dc5d69801fe0b4aa to your computer and use it in GitHub Desktop.
Save gartes/7ff41ca92bc513f2dc5d69801fe0b4aa to your computer and use it in GitHub Desktop.
Rules htaccess

htaccess


Содержание:

Links:


Содержание

КАК СДЕЛАТЬ 301-РЕДИРЕКТ В ФАЙЛЕ .HTACCESS? ПРИМЕРЫ И ПРАВИЛА НАСТРОЙКИ
https://pixelplus.ru/samostoyatelno/stati/indeksatsiya/301-redirekt.html

Как убрать .html в конце адреса каждой веб-страницы сайта, без использования php?
https://qna.habr.com/q/78158?_ga=2.4322682.875072626.1585983575-533571880.1579339688
# Перенапровление https://www.kfhbelous.ru/?id=11  => https://www.kfhbelous.ru/prajs-list
RewriteCond %{QUERY_STRING} id=11
RewriteRule (.*) https://www.kfhbelous.ru/prajs-list? [R=301,L]

Содержание


Переадресация с http на https: (2021-12-5, 18:49)

### Переадресация с http на https:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Переадресация с www to non-www (2021-12-5, 18:48)
### Переадресация с www на to non-www:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

Содержание


Максимальный размер загружаемого файла PHP в файле

# Максимальный размер загружаемого файла PHP в файле
# https://www.a2hosting.com/kb/developer-corner/php/using-php-directives-in-custom-htaccess-files/setting-the-php-maximum-upload-file-size-in-an-htaccess-file
php_value upload_max_filesize 20M
php_value post_max_size 21M

Замена "_" (нижнее подчёркивание) на "-" (тире)

# Замена "_" (нижнее подчёркивание) на "-" (тире)
RewriteRule ^(.*)_(.*)_(.*)_(.*)$ /$1-$2-$3-$4 [R=301,L]
RewriteRule ^(.*)_(.*)_(.*)$ /$1-$2-$3 [R=301,L]
RewriteRule ^(.*)_(.*)$ /$1-$2 [R=301,L]

Переадресация на без html

#Переадресация на без html
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R=301]

Если в ссылке видим zd, ulpl ......

# Если в ссылке видим zd, ulpl, sad, pam, lich или most, то добавляем перед ними istoriya-peterburga/
RewriteRule ^(zd|ulpl|sad|pam|lich|most)(.*) /istoriya-peterburga/$1$2 [R=301,L]

Установить кодировку

# Установить кодировку
AddDefaultCharset UTF-8
AddDefaultCharset WINDOWS-1251

Редирект && слеши

# https://sezzam.com.ua/redirekt-s-dvuh-sleshey/
# Редирект с двух слешей
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /{2,}
RewriteRule ^(.*) /$1 [R=301,L]

# Второй вариант
RewriteCond %{REQUEST_URI} ^(.*)/{2,}(.*)$
RewriteRule . %1/%2 [R=301,L]

# Третий вариант
RewriteCond %{THE_REQUEST} //
# Проверяем, повторяется ли слеш (//) более двух раз.
RewriteRule .* /$0 [R=301,L]
# Исключаем все лишние слеши.

Добавлять в отчет все ошибки PHP

// Добавлять в отчет все ошибки PHP
error_reporting(-1);

PHP error handling для отладки или разработки

# PHP error handling для отладки или разработки
php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on
php_flag log_errors on
php_flag ignore_repeated_errors off
php_flag ignore_repeated_source off
php_flag report_memleaks on
php_flag track_errors on
php_value docref_root 0
php_value docref_ext 0
# Путь должен соответствовать настройкам сервера
php_value error_log /home/virtwww/w_ekgazeta-ru_c408a262/http/PHP_errors.log
# [see footnote 3] # php_value error_reporting 999999999
php_value error_reporting -1
php_value log_errors_max_len 0

# Настройки доступа к файлу логов
# Путь должен соответствовать настройкам сервера
<Files /home/virtwww/w_ekgazeta-ru_c408a262/http/PHP_errors.log>
Order allow,deny
Deny from all
Satisfy All
</Files>

Включение GZIP

hostinger.com.ua

# Включение GZIP
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/xml
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/opentype
# For Older Browsers Which Can't Handle Compression
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment