Asked Jul 14th, 2021 6:51 a.m. 188 1 0
  • 188 1 0

Convert htaccess to nginx

  • 188 1 0

Chào mọi người hiện tại em đang có file .htaccess như này

## Uncomment (remove # ONLY NOT ##) line below if installed in folder and add folder name after /
DirectoryIndex index.php

<IfModule mod_expires.c>
  ExpiresActive On
 # Images
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/gif "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 year"
  ExpiresByType image/x-icon "access plus 1 year"
  # Video
  ExpiresByType video/webm "access plus 1 year"
  ExpiresByType video/mp4 "access plus 1 year"
  ExpiresByType video/mpeg "access plus 1 year"
  # Fonts
  ExpiresByType font/ttf "access plus 1 year"
  ExpiresByType font/otf "access plus 1 year"
  ExpiresByType font/woff "access plus 1 year"
  ExpiresByType font/woff2 "access plus 1 year"
  ExpiresByType application/font-woff "access plus 1 year"
  # CSS, JavaScript
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType text/javascript "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
  # Others
  ExpiresByType application/pdf "access plus 1 month"
  ExpiresByType image/ "access plus 1 year"
ExpiresByType application/pdf "access plus 1 days"
ExpiresByType text/x-javascript "access plus 1 days"
ExpiresByType image/x-icon "access plus 1 days"
ExpiresDefault "access plus 1 days"
ExpiresByType application/javascript "access plus 1 month" #sssss
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
<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 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/
 AddOutputFilterByType DEFLATE font/ttf
 AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/opentype
Header unset ETag
FileETag None
<FilesMatch ".(js|css|html|htm|php|xml)$">
SetOutputFilter DEFLATE
# BEGIN Compress text files

<IfModule mod_deflate.c>

<FilesMatch "\.(css|js|x?html?|php)$">

SetOutputFilter DEFLATE



# END Compress text files
# BEGIN Cache-Control Headers

<IfModule mod_headers.c>

<FilesMatch "\.(ico|jpe?g|png|gif|swf)$">

Header set Cache-Control "max-age=2592000, public"


<FilesMatch "\.(css)$">

Header set Cache-Control "max-age=604800, public"


<FilesMatch "\.(js)$">

Header set Cache-Control "max-age=216000, private"


<FilesMatch "\.(x?html?|php)$">

Header set Cache-Control "max-age=600, private, must-revalidate"



# END Cache-Control Headers
# BEGIN Remove Last-Modified Header

<IfModule mod_headers.c>

Header unset Last-Modified


# END Remove Last-Modified Header
<files config.php>
order allow,deny
deny from all


# 1 Month for all your static assets

<filesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|woff)$">

Header set Cache-Control "max-age=2592000, public"


# 1 DAYS for rss feeds and robots

<filesMatch ".(xml|txt)$">
Header set Cache-Control "max-age=86400, public, must-revalidate"
<filesMatch ".(html|htm)$">
Header set Cache-Control "max-age=14400, must-revalidate"
<IfModule mod_deflate.c>
# compress text, html, javascript, css, xml:
AddType x-font/otf .otf
AddType x-font/ttf .ttf
AddType x-font/eot .eot
AddType x-font/woff .woff
AddType image/x-icon .ico
AddType image/png .png
FileETag None
<Files *.js.gz>
AddType "text/javascript" .gz
  AddEncoding gzip .gz
<Files *.css.gz>
  AddType "text/css" .gz
  AddEncoding gzip .gz

<IfModule mod_rewrite.c>
	<IfModule mod_negotiation.c>
	    Options -MultiViews -Indexes

	RewriteEngine On

	# Handle Authorization Header
	RewriteCond %{HTTP:Authorization} ^(.*)
	RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

	## Uncomment the following line to use the multi-domain feature
	# RewriteCond %{HTTP_HOST} ^$ [NC]
	# RewriteRule ^(.*)$$1 [R=301,L]

	#Rewritebase /
	## Admin Panel
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteRule ^admin/(.*)?$ admin/index.php?a=$1 [QSA,NC,L]

	## Sitemap ###
	RewriteRule ^sitemap.xml$ sitemap.php

	## Application Handler
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteRule ^(.*)?$ index.php?a=$1	[QSA,NC,L]

	## Error 404 ##
	ErrorDocument 404 /index.php?a=404
<Files 403.shtml>
order allow,deny
allow from all

nhờ mọi người convert qua nginx giúp em ạ em có dùng qua 1 số web nhưng cứ lỗi, và em cũng chưa quen với nginx mong mọi người chỉ dẫn ạ 😄

Let's register a Viblo Account to get more interesting posts.