Edit .htaccess on plugin deactivate - .htaccess

I am trying to add rewrite rules in .htaccess during plugin activation. How can I edit/roll-back rewrite rules in .htaccess on plugin deactivation?
function add_to_htaccess( $rules ) {
$content = <<<EOD
\nAddOutputFilterByType 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
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/x-httpd-fastphp
AddOutputFilterByType DEFLATE image/svg+xml
SetOutputFilter DEFLATE\n\n
EOD;
return $content . $rules;
}
add_filter('mod_rewrite_rules', 'add_to_htaccess');
function myplugin_enable_flush_rules() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
register_activation_hook( __FILE__, 'myplugin_enable_flush_rules' );
The above function adds rewrite rules with in default WordPress rules lies between # BEGIN WordPress and # END WordPress. What could I do to add it separately (at the bottom of .htaccess ?)

I have managed to do this at my own. Below is the function I have added.
function myplugin_deactivate() {
// This will remove the rewrite rules
remove_filter('mod_rewrite_rules', 'add_to_htaccess');
global $wp_rewrite;
// Flush the rewrite rules
$wp_rewrite->flush_rules();
}
register_deactivation_hook( __FILE__, 'myplugin_deactivate' );

Related

why Gzip Compression htaccess not working

I copied below mentioned Gzip code in htaccess file which was saved in hostgator root folder.
But after I check from Gzip testing tools it makes no different. I tried many codings and they also did not work.
<ifmodule mod_deflate.c>
# 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
</ifmodule>

serve compressed file with no file extension with .htaccess

I have a website chat plugin script that I've made a local copy of, and uploaded to our website: www.example.com/js/default.
webpagetest.org reports this file is uncompressed.
In .htaccess, we have:
<IfModule mod_deflate.c>
AddType x-font/woff .woff
AddType x-font/ttf .ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE font/opentype font/ttf font/eot font/otf
</IfModule>
Is this not enough to compress www.example.com/js/default ?
If not, what do we need to add to .htaccess? Thanks.

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");

Including GZip, Expire headers, and etag; what else can be done to optimize .htaccess to improve a site's performance?

# 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
#Expire Header
<FilesMatch "\.(ico|jpg|jpeg|png|gif|js|css|swf)$">
ExpiresDefault "access plus 2 hours"
</FilesMatch>
FileETag none
This is what I found but I don't know if this is the best solution to speed up my web site

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

Resources