2021年4月22日 星期四

.htaccess應用

去除WWW
RewriteEngine On 

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



從URL去除index.php
RewriteEngine On 

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ https://example.com/ [R=301,L] 



Bluehost伺服器 GZip 網頁壓縮
<ifmodule mod_deflate.c>
 AddOutputFilterByType DEFLATE image/gif image/png image/jpeg image/x-icon application/pdf application/javascript application/x-javascript text/plain text/html text/css text/x-component text/xml application/json
 </ifmodule>




指定目錄,禁止執行.php、.html、.js之檔案
RewriteEngine On RewriteCond % !^$

RewriteRule uploads/(.*).(php)$ – [F]
RewriteRule uploads/(.*).(html)$ – [F]
RewriteRule uploads/(.*).(js)$ – [F]


沒有留言:

張貼留言

.htaccess應用

去除WWW RewriteEngine On RewriteCond %{HTTP_HOST} ^www\.example\.com $ [ NC ] RewriteRule ^(.*) $ https: / /example.com/ $1 [ R = 301...