I'm looking for a simple one line code that will use gzip to compress css, html, js, and php files on the web server. How can I do this with the .htaccess file or php.ini file? (My css and js files are in seperate folders in the root directory)
<Files *>
#Compress
SetOutputFilter GZIP
</Files>
You're most likely looking for mod_deflate module in Apache. Enable it in your httpd.conf and also enable .htaccess then add this code in your .htaccess under DOCUMENT_ROOT:
<FilesMatch "\\.(js|css|html|htm|php)$">
SetOutputFilter DEFLATE
</FilesMatch>
Related
I'm using SSI on my website.
I have got html files which represent my site and shtml files which I include into some of these html files using the include command of SSI.
Is there any way to deny users from seeing the shtml files which I include?
I tried the following:
<FilesMatch "\.(shtml?)$">
Order allow,deny
Deny from all
allow from 127.0.0.1
</FilesMatch>
And here is the whole part of my current htaccess file which may be important:
allow from all
<Files ~ "^\.htaccess|^README\.txt">
Order allow,deny
Deny from all
</Files>
<FilesMatch "\.(shtml?)$">
Order allow,deny
Deny from all
allow from 127.0.0.1
</FilesMatch>
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
AddOutputFilter INCLUDES .html
Here is my current .htaccess file
#tell browser how to deal with compressed content
<Files *.css.gz>
AddType "text/css" .gz
AddEncoding gzip .gz
</Files>
<Files *.js.gz>
AddType "application/javascript" .gz
AddEncoding gzip .gz
</Files>
<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 2592000 seconds"
ExpiresByType text/html "access plus 1 seconds"
</ifModule>
<ifModule mod_headers.c>
<filesMatch "\.(js|css|png|jpg|ico|pdf)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>
</ifModule>
RewriteEngine on
RewriteBase /
#Cache-Friendly File Names
RewriteRule ^(.*)-([0-9]+)\.(.*)$ $1.$3
#try to use precompressed files whenever possible
RewriteCond %{HTTP:Accept-Encoding} .*gzip.*
RewriteRule ^(.*)\.css$ web_inc/$1.css.gz
RewriteRule ^(.*)\.js$ web_inc/$1.js.gz
The web page is mostly static .html files and large .js and .css files that use ajax calls for any dynamic content. Since all files in the html are refereed to by name-01.js if I make an update to the .js I just increase the version number and the browser recaches.
I wish to prevent the web browser from ever redownloading any file type except .html or .php. Is there a way to not have to list every file type I use and how can I explicitly set php to 0 sec for mod_expires?
I've been trying to get .HTML files to process like .PHP files using the .htaccess file on my localhost. I've used the following one by one,
AddHandler application/x-httpd-php55 .html .htm
AddHandler application/x-mapp-php55 .php .html
AddHandler application/x-httpd-php .html .htm
AddHandler application/x-httpd-php5-script .html .htm
But none of the above worked for me.
I am using php5.5 and apach 2.4 in xampp
Is there any other configs in apache config file?
Need help
This question is clear, but no proper answers yet given. It seems nobody can answer it. Too bad, but it can happen
This has worked for me in the past.
AddHandler application/x-httpd-php .html
Also note that you must have mod_mime activated in Apache.
Also I assume your server is allowing the use of an .htaccess file and the AddHandler directive with either :-
AllowOverride All
or
AllowOverride FileInfo
My DEV HTACCESS looks like this
<IfModule mime_module>
#AddHandler application/x-httpd-ea-php72 .php .php7 .phtml
AddType application/x-httpd-php .php .htm .html .shtml
</IfModule>
I switch the Hashing for LIVE server though.
Hope this helps
I want to automatically add the X-Robots-Tag header for all php, htm, html pages EXCEPT /index.php and forgot.php.
This would cover all of them:
<FilesMatch "\.(htm|html|php)$">
<IfModule mod_headers.c>
Header set X-Robots-Tag "noindex, nofollow"
</IfModule>
</FilesMatch>
But how can I exclude /index.php and /forgot.php from that FilesMatch directive?
What I want it to do :
Valid for all .htm, .html, .php files
Exclude for /index.(htm|html|php), /forgot.(htm|html|php), but not */index.php should be valid.
Hopefully that makes sense... I just want to exclude it from those two specific files at the base of the site.
UPDATE:
Playing around with this on tester, but still have some issues :
(?!.*/(index.php|forgot))(^.*\.(php|htm|html)$)
this is excluding URLs like www.mysite.com/folder/index.php
I was looking at this wrong the whole time. Here is what I am using :
# BEGIN noindex,nofollow on all but login and forgot page
<IfModule mod_env.c>
RewriteRule ^(index\.php|forgot\.php)$ - [E=exclude:1]
<FilesMatch "\.(php|html?)$">
<IfModule mod_headers.c>
Header set X-Robots-Tag "noindex, nofollow" env=!exclude
</IfModule>
</FilesMatch>
</IfModule>
What have you tried? Have you tried something like this?
<FilesMatch "^(^index|^forgot)\.(htm|html|php)$">
Just want to point you in the right direction. I haven't tried this yet, but it's probably going to be a bit greedy and match files like index_example.php as well. Not just index.php.
These guys have an excellent reference on RegEx: http://www.regular-expressions.info/
I try to make my site run with seo when i access
mysite.com/search/eminem/1/video.html
to give me the results for this url
mysite.com/index.php?search=eminem&page=1&type=video
And it show me the search page but with no results no images or javascripts etc. Is like css and js's are not implemented
this is my .htacces code
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^search/(.*)/(.*)/(.*).html?$ index.php?search=$3&page=$2&type=$1 [L]
<IfModule mod_deflate.c>
<FilesMatch "\.(php|js|css|mp3|wmv|flv|html|htm)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
</IfModule>
You either need to make all your relative links (for images, CSS, JavaScript, etc) to absolute links with a leading slash, or add this to the header of your index.php content:
<base href="/">