I'm dealing with a Magento site that has a 3rd party CMS integration. When I enable Mod_deflate via the .htaccess file most of the site works well. All of the pages that pull the information from the CMS show "gobbledy-gook" and it apprears that what is supposed to apprear is not getting decompressed.
I'm attempting to simply exclude parts of the site that employ the CMS from compression (including the home page), however, I'm not sure if I can exclude urls from mod_deflate via SetEnvIfNoCase. A yea, nea or syntax help would be appreciated.
Here are my lines:
SetEnvIfNoCase Request_URI "(/site/*)" no-gzip dont-vary #exclude www.example.com/site/
SetEnvIfNoCase Request_URI "(/)" no-gzip dont-vary #only exclude homepage or index.php
So here is the solution. If you need to gzip your site, but for some reason parts of your site don't react well to gzip compression - such as the 3rd party CMS integration with Magento. Enable mod-Deflate in your .htaccess file and include this line:
SetEnvIf Request_URI ^/yourdir(.*) no-gzip dont-vary
yourdir being the directory where your cms is installed.
From my reading of the Apache docs you would want
SetEnvIf
not
SetEnvIfNoCase
AllInOne, would the correct syntax be?:
SetEnvIf Request_URI "(/site/*)" no-gzip dont-vary
SetEnvIf Request_URI "(/)" no-gzip dont-vary
Related
I have a web server using apache2, and I want to silently redirect some pages.
So if an user try to access "http://website.com/test.php", the page at "http://website.com/fool.php" will be used instead. And i need to do that for several pages, not just test.php.
I though I could use the mod_rewrite module for this purpose, but I cant get it working.
I tried adding in apache2.conf, so i could have at least just a redirection for now (not silent):
RewriteEngine on
RewriteRule "^/test.php$" "/fool.php"
or
<Directory "/var/www">
RewriteEngine on
RewriteBase "/var/www"
RewriteRule "^/test.php$" "/fool.php"
</Directory>
This result in the test.php not being redirected at all (it still can be accessed), but also, it breaks my custom 404 and 403 pages with the error "ForbiddenYou don't have permission to access this resource.Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.".
Apache2 is not complaining about the syntax when i restart it.
Setting it in my sites-enabled config leads to the same result.
Note that the goal is not to prevent the direct access to test.php, and the request must result in a 200 success code.
There may be something i do not understand, because searching on the net, it looks like it's the way to achieve this.
You may try an alternative method: use the .htaccess file. (place the file in the root directory of your site)
For example:
RewriteEngine on
RewriteRule ^/test.php$ /fool.php [L]
I have all my folders and files in www.mysite.com/magento/ and my home page base url is www.mysite.com/magento/. I need to change this url to only www.mysite.com and if possible I don't wanna move my files from /magento/ to the back folder.
If I use System - Configuration - Web from my magento-admin-panel, it doesn't work and I can't connect to panel.
You should be able to accomplish that using .htaccess and RewriteBase.
Here's commented out example in Magento .htaccess sample:
############################################
## you can put here your magento root folder
## path relative to web root
RewriteBase /magento/
That should do the trick in your case.
You can read more about RewriteBase here: http://httpd.apache.org/docs/current/mod/mod_rewrite.html#page-header
Edit: In the web root, you'll need some sort of rewrite to Magento root directory:
RewriteEngine on
RewriteCond %{REQUEST_URI} !magento/
RewriteRule (.*) /magento/$1 [L]
Keep in mind that there are all just untested examples that should point you in the right direction. :)
Cheers.
We have a desktop and a mobile version of our webapp.
The desktop url is more prominent and so we would like to redirect the user to the mobile version in case the request is for the desktop url from a mobile device.
In the apache config we have the mod_rewrite module
and my config at present looks like this
<IfModule mod_rewrite>
RewriteEngine On
RewriteCond %{x-wap-profile} ^https?://
RewriteRule ^/(.*) http://google.com [L,R]
</IfModule>
At this point this is the only rewrite rule that we have so I'm not sure if L is required because this is the first and last rule anyway.
I have just indicated redirection to google.com for testing purposes
I'm not sure if my condition check is right.I couldn't figure out how to check for existence of a header.Is that what is wrong?If yes,please let me know how to specify the RewriteCond
How I'm Testing?
I'm testing from a Firefox browser and using the Modify headers plugin to simulate the mobile request.I'm adding the x_wap_profile header.
However I don't see any redirect happening with this config.Can you please let me know where I'm going wrong?I would also appreciate if there is any logging that can be introduced here to verify if this rule is being trigerred.I don't see any errors though with the current modified config.
To check for an arbitrary header in mod_rewrite (i.e. a header not in this list), the syntax is:
RewriteCond %{HTTP:x-wap-profile}
This one seems to work:
RewriteEngine On
RewriteCond %{HTTP:x-wap-profile} ^.+
RewriteRule .* http://google.com [L,R]
piotrek#piotrek-Vostro-2520:~/vhosts/localhost$ curl http://localhost/
OKOK
piotrek#piotrek-Vostro-2520:~/vhosts/localhost$ curl -H 'x-wap-profile: abcd' http://localhost/
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved here.</p>
<hr>
<address>Apache/2.4.6 (Ubuntu) Server at localhost Port 80</address>
</body></html>
Change it to make it work for https inside header.
Docs here: http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritecond in section Other things you should be aware of:.
I have developed a kohana project 2.4 version, with i has been developed by configuring virtual host and we are accessing it using some domain aa.com, now i have to move the project to folder named kohana and make it access via aa.com/kohana. If i access it this way then my url changes, So the css & js file are not included since the src url i have provided like /public/css/ so it's not working, same goes for calling a controller. like il be calling a controller using this format /user/login/. now the url when i click to shows like aa.com/user/login which is not found, in turn it should automatically comes like aa.com/kohana/user/login. Is there any way by changing the htaccess file or hacking routes.php file. ?
I should able to automatically append /kohana/ before the url.
Please suggest me a method how it can be achieved.
Yes there is!
I've only started after kohana 3.0 but you can just change the rewritebase.
In your .htacces it probably says "rewritebase /"
Change this to your new directory. "rewritebase /kohana/"
If 2.4 has a bootstrap (i'm not sure) somewhere it should say "base_url". You change this the same as the .htaccess. /kohana/.
edit: here's an example:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /kohana/
# Protect application and system files from being viewed
RewriteRule ^(application|modules|system) - [F,L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT,L]
I have the following rewrite rule, but nothing is hapenning at all when I try to use it. I have the file in the directory server.blahblahblah.com/todo and the following is my .htaccess file:
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^tasks/view/([0-9]+)?/$ controller.php?task=view&id=$1
RewriteRule ^tasks/view/([0-9]+)\.xml$ controller.php?task=viewxml&id=$1
RewriteRule ^tasks/new?/$ controller.php?task=new
RewriteRule ^tasks/delete/([0-9]+)?/$ controller.php?task=delete&id=$1
RewriteRule ^tasks/completed/([0-9]+)?/$ controller.php?task=complete&id=$1
RewriteRule ^tasks?/$ controller.php?task=home
Does anyone know why this won't work at all?
Thanks,
Tim
If nothing happens at all, it might be that you didn't enable .htaccess files for your site. To do that, change your site configuration (/etc/apache2/sites-enabled/<yoursite>) to include AllowOverride All instead of AllowOverride None (the default). But mind the performance disadvantage - you could also put the rules directly in the site configuration.
In case that doesn't solve it, look at the Apache logs in /var/log/apache2/*.