My .htaccess file might be incorrect - .htaccess

I am creating a .htaccess file that will compress my website. I copied and pasted the gzip code but when I tested the website it did not compress.
I placed my .htaccess file in the public/html directory along with other web pages, and I made sure to change the file name from the original txt file.
Here is the code from the .htaccess file
<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
ErrorDocument 400 /400.html
ErrorDocument 401 /401.html
ErrorDocument 403 /403.html
ErrorDocument 404 /404.html
ErrorDocument 500 /500.html
ErrorDocument 502 /502.html
ErrorDocument 504 /504.html
AddType application/octet-stream .avi .mpg .mov .pdf .xls .mp4 .doc
# disable directory browsing
Options All -Indexes
<FilesMatch ".(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$">
Order Allow,Deny
Deny from all
</FilesMatch>
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# Or, compress certain file types by extension:
<files *.html>
SetOutputFilter DEFLATE
</files>

first thing first, make sure your apache has mod_gzip or mod_deflate loaded
run this and check it
print_r(apache_get_modules());
note: for apache 2+ you need mod_deflate, for earlier versions mod_gzip (you may need to alter your htaccess file in that case)

Related

gzip/mod_deflate does not work on apache2, ubuntu, amazon ec2

I have tried everything and I cannot get gzip or mod_deflate to work. I have placed almost everything into my .htaccess file as well as my apache2.conf file. They all do not work.
Here is my server configuration:
Amazon EC2 with everything forced to https://www. with Apache (apache2) and Ubuntu. Every time I run my website through an online tester, it says that my gzip is not working/enabled. I checked multiple times and my mod_deflate and my mod_filter are both installed and enabled and running.
I've also restarted my server and restarted apache a few times but it still does not recognize that my files are gzip'ed. Here's one of the multiple codes I've tried to add from gtmetrix:
<IfModule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
# Remove browser bugs (only needed for really old browsers)
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
</IfModule>
I ran my website through gtmetrix and it says my .js files and my .css files are not compressed through gzip. What is wrong?
Okay, my index is a .php page so I had to add this in my index.php page:
ob_start("ob_gzhandler");

htaccess searching for files

I am having trouble with .htaccess and I am on ubuntu, the problem is, when I write an uri like this,
127.0.0.1/u
the .htaccess searches for a file and when It finds a file that starts with that letter, the uri changes directly to this,
http://127.0.0.1:8000/u/?tab_id=u
But, it should be like this,
http://127.0.0.1/u
It happens beacuse there are files that start with u like, user-edit.php and user-login.php ....
when I write
http:://127.0.0.1/a
or any uri that does not match any file, it runs perfect, this is my .htaccess code
RewriteEngine On
RewriteRule ^([//a-zçöşığüA-ZÇÖŞİĞÜ0-9_-]+)$ tab.php?tab_id=$1 [QSA,L]
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
<files *.html>
SetOutputFilter DEFLATE
</files>
I searched a lot, but cannot find the solution, thank you for any help
Sounds like a MultiViews problem. Disable this by using
Options -MultiViews

ErrorDocument is not working for 401 response

I am trying to redirect to a custom error page using a redirect in .htaccess. Please check the site jobslanda.com. The line ErrorDocument 401 401.php is not working. I am using the following configuration in .htaccess:
RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)/([\w.,]+)/([\w.,]+)/([\w.,]+)/([\w.,]+)/([\w.,]+)/([\w.,]+)$ job.php?j=$1
RewriteRule ^([a-zA-Z0-9]+)/([\w.,]+)/([0-9]+)$ sameIndustryJobs.php?i=$1&c=$2&p=$3
RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([\w',]+)/([0-9]+)$ sameCatagoryJobs.php?c=$1&s=$3&p=$4
RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([\w.,]+)/([0-9]+)$ sameCityJobs.php?c=$1&cn=$4&p=$5
RewriteRule ^([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([\w.,]+)/([0-9]+)$ sameQualificationJobs.php?q=$1&cn=$5&p=$6
ErrorDocument 401 401.php
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
Is it because you did not spell ".htaccess" correctly? (And your Apache installation is not picking up the file?)
Where do you have the 401.php file located on your web server? Typically the ErrorDocument directive should begin with a / and reference a page relative to your web root.
Reference:
http://httpd.apache.org/docs/2.0/mod/core.html#errordocument
You don't appear to have a page at:
http://jobslanda.com/401.php
Oddly, that's returning a 302 redirect to a page called 404.php.

Can deflate/gzip be with "deny from all"?

I am kind of confused with the .htaccess file. I want gzip compression and deny from all in a directory. My question is can "deny from all" be with gzip compression or it has any problems?
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# Or, compress certain file types by extension:
<Files *.html>
SetOutputFilter DEFLATE
</Files>
deny from all
deny from all means no one can access the directory directly via a URL. Any content sent to the browser from that directory has to come via a server-side script placed elsewhere, which means that .htaccess is bypassed entirely - so the compression won't take place.
Your server-side script will therefore have to perform the compression on its own using http_deflate before outputting the data from those files.

getting error 500 when trying to use gzip with .htaccess

I'm trying to use gzip on my site.
I'm trying to compress, php, css and js files. The server is apache 1.3, and the code I have in the .htaccess file is:
# compress all text & html:
AddOutputFilterByType DEFLATE text/html text/plain text/xml
But when I upload this, I just get an Error 500 page.
Any ideas.
Try this
<Files *>
#Compress
SetOutputFilter GZIP
</Files>
Or this
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript text/javascript
</ifmodule>
AddOutputFilterByType doesn't appear to be available on Apache 1.3 (src). I believe you'll need to use mod_gzip instead.
"Compatibility: Available in Apache 2.0.33 and later; deprecated in Apache 2.1 and later"

Resources