I have developed a really easy web application based on CakePHP. I am currently running some speed test and in order to optimise the performance I used .htaccess to turn on some Apache modules such as mod_deflate. However I am struggling with the expiring headers.
I have found a couple of solutions and this is my current htaccess:
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
ExpiresDefault "access plus 1 year"
</FilesMatch>
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/release
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Using YSlow I can see that some of the assets have the right value, however some js/css files coming form plugins (/app/Plugins/X/webroot) are not changing the value.
I have also tried to add a htaccess file in the Plugin folder as well but nothing changed. I am running out of ideas.
Please, check plugin assets seems all your plugin static files handled by dispatcher this is reason of wrong headers. So, try to lead official documentation and create symbolic link
Related
beginner here :). So I have a wordpress website on which I added some of my own database tables and php & sql scripts. Users can login on my website (independently of wordpress) and then add content into my database tables, which is then shown on the website.
I have just switched to HTTPS with a certificate from Let's encrypt and I have a big problem. The URL's to my pages (those which are NOT wordpress) are not working anymore and are showing a 404 error. I spent a week trying to fix the issue but I just can't do it with my limited skills. Here is some info below.
The script which is generating the pages has the following code:
$testurl = 'https://www.example.com/test-pages/'.sanitize_title($row['c2']).'-'.$row['id'];
In .htaccess, I have the following line:
RewriteRule ^test-pages/[_a-z0-9-]+\-{1}([0-9]+)$ /test-pages?id=$1 [P]
These two should properly rewrite the urls, right (though I'm not sure where $testurl is called, the line of code is just sitting there in my script)? The particular lines of code were written by somebody else, so I'm not sure if I'm missing something, but they worked for years with plain old http!
I think I took the proper steps to set up https and all the wordpress pages are working.
Also, interestingly, if I try to access the pages with http, it redirects to https://www.example.com/test-pages?id= , which I guess is the standard url created out of the database, which the scripts presented above used to overwrite. And it shows the page fine. So I can make things work linking to pages in that way, but I don't want that.
At this point I have no idea what to do, normally I manage to overcome such issues, but not this time. I searched stackoverflow for solutions too, but found nothing to make sense for me. Any ideas? Is the problem here, or somewhere else? Hopefully I managed to explain the issue properly and somewhat coherently. Thank you!
EDIT: I added the htaccess file. I don't know exactly what more I should add.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.maindomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.maindomain\.com$
RewriteCond %{HTTPS} off
RewriteRule ^/?$ "https\:\/\/example\.com" [R=301,L]
RewriteRule ^test-pages/[_a-z0-9-]+\-{1}([0-9]+)$ /test-pages?id=$1 [P]
RewriteRule ^test-profiles/[_a-z0-9-]+\-{1}([0-9]+)$ /test-profiles?id=$1 [P]
# BEGIN rlrssslReallySimpleSSL rsssl_version[3.3.5]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
# END rlrssslReallySimpleSSL
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 month"
</IfModule>
## EXPIRES CACHING ##
<Files 403.shtml>
order allow,deny
allow from all
</Files>
# Wordfence WAF
<Files ".user.ini">
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>
</Files>
# END Wordfence WAF
<files wp-login.php>
order deny,allow
deny from all
allow from **.***.**.**
</files>
ErrorDocument 401 default
ErrorDocument 403 default
ErrorDocument 404 default
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php74” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php74 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit```
I am working on setting up a MyBB forum with https enabled. I've got TLS set up and enabled and https redirect is enabled by my host.
Direct links like http://www.example.com/index.php and example.com/index.php correctly redirect to https://www.example.com/index.php. But any any attempts to go straight to to https://www.example.com/ go to https://www.www.example.com/. Does anyone have any ideas about what might cause this?
My .htaccess file is as follows (mostly taken from MyBB's default .htaccess setup.)
Options -MultiViews +FollowSymlinks -Indexes
<FilesMatch "\.(php|html)$">
Header set Cache-Control "private, no-cache"
Header set Pragma "no-cache"
</FilesMatch>
#
# If mod_security is enabled, attempt to disable it.
# - Note, this will work on the majority of hosts but on
# MediaTemple, it is known to cause random Internal Server
# errors. For MediaTemple, please remove the block below
#
<IfModule mod_security.c>
# Turn off mod_security filtering.
SecFilterEngine Off
# The below probably isn't needed, but better safe than sorry.
SecFilterScanPOST Off
</IfModule>
#
# MyBB "search engine friendly" URL rewrites
# - Note, for these to work with MyBB please make sure you have
# the setting enabled in the Admin CP and you have this file
# named .htaccess
#
<IfModule mod_rewrite.c>
RewriteEngine on
RedirectMatch ^/$ news.php
RewriteRule ^forum-([0-9]+)\.html$ forumdisplay.php?fid=$1 [L,QSA]
RewriteRule ^forum-([0-9]+)-page-([0-9]+)\.html$ forumdisplay.php?fid=$1&page=$2 [L,QSA]
RewriteRule ^thread-([0-9]+)\.html$ showthread.php?tid=$1 [L,QSA]
RewriteRule ^thread-([0-9]+)-page-([0-9]+)\.html$ showthread.php?tid=$1&page=$2 [L,QSA]
RewriteRule ^thread-([0-9]+)-lastpost\.html$ showthread.php?tid=$1&action=lastpost [L,QSA]
RewriteRule ^thread-([0-9]+)-nextnewest\.html$ showthread.php?tid=$1&action=nextnewest [L,QSA]
RewriteRule ^thread-([0-9]+)-nextoldest\.html$ showthread.php?tid=$1&action=nextoldest [L,QSA]
RewriteRule ^thread-([0-9]+)-newpost\.html$ showthread.php?tid=$1&action=newpost [L,QSA]
RewriteRule ^thread-([0-9]+)-post-([0-9]+)\.html$ showthread.php?tid=$1&pid=$2 [L,QSA]
RewriteRule ^post-([0-9]+)\.html$ showthread.php?pid=$1 [L,QSA]
RewriteRule ^announcement-([0-9]+)\.html$ announcements.php?aid=$1 [L,QSA]
RewriteRule ^user-([0-9]+)\.html$ member.php?action=profile&uid=$1 [L,QSA]
RewriteRule ^calendar-([0-9]+)\.html$ calendar.php?calendar=$1 [L,QSA]
RewriteRule ^calendar-([0-9]+)-year-([0-9]+)-month-([0-9]+)\.html$ calendar.php?calendar=$1&year=$2&month=$3 [L,QSA]
RewriteRule ^calendar-([0-9]+)-year-([0-9]+)-month-([0-9]+)-day-([0-9]+)\.html$ calendar.php?action=dayview&calendar=$1&year=$2&month=$3&day=$4 [L,QSA]
RewriteRule ^calendar-([0-9]+)-week-(n?[0-9]+)\.html$ calendar.php?action=weekview&calendar=$1&week=$2 [L,QSA]
RewriteRule ^event-([0-9]+)\.html$ calendar.php?action=event&eid=$1 [L,QSA]
<IfModule mod_env.c>
SetEnv SEO_SUPPORT 1
</IfModule>
</IfModule>
#
# If Apache is compiled with built in mod_deflade/GZIP support
# then GZIP Javascript, CSS, HTML and XML so they're sent to
# the client faster.
#
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/css text/html application/xhtml+xml text/xml application/xml text/plain text/x-component application/javascript application/x-javascript application/rss+xml application/atom+xml application/json application/manifest+json application/x-web-app-manifest+json application/vnd.ms-fontobject application/font-sfnt application/font-woff application/font-woff2 image/svg+xml image/x-icon
</IfModule>
# Note: You are able to choose a different name in the Admin CP. If you've done that you need to change it here too
<Files "error.log">
Require all denied
</Files>
This turned out to be a browser caching issue.
Had our website up for a while, and I'm now working on a contact form with a simple PHP mailer. For some reason though, all .php files on the directory are 403 Forbidden. For example:
http://www.bawkdesign.co.uk/mailer.php
Even trying .php files that don't exists results in a 403.
http://www.bawkdesign.co.uk/idonoexist.php
Perhaps there's something in .htaccess causing this? If there is I can't see it! The website is hosted with GoDaddy (Yup, not my choice)
I've checked the file and folder permissions and they all seem good too. Any help is really appreciated.
.htaccess file
#Rewrite urls to remove extensions
Options FollowSymLinks
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC]
RewriteRule ^(.+[^/])/$ http://%{HTTP_HOST}/$1/ [R=301,L]
RewriteCond %{HTTP_HOST} ^bawkdesign.com [NC]
RewriteRule ^(.*)$ http://www.bawkdesign.com/$1 [L,R=301]
#404 Page Not Found
ErrorDocument 404 /404
#Enable server side compression
AddOutputFilterByType DEFLATE text/text text/html text/php text/plain text/xml text/css application/x-javascript application/javascript
#Enable Mod_Expires for browser caching
ExpiresActive On
ExpiresDefault A0
# Set timing for cached files to expire after
<FilesMatch "\.(jpg|jpeg|png|gif|txt|xml|php|js|css|html)$">
ExpiresDefault A704800
Header append Cache-Control "public"
</FilesMatch>
#Define the charset
AddDefaultCharset utf-8
Hi I am getting 500 Internal server Error when am trying to run my code in wampserver which is working absolutely
My .htaccess file is in wamp/www/site foloder and all other code is also in same folder
so should i put site somewhere in .htaccess file because online my code is in root folder
My .htaccess code:
RewriteEngine on
FileETag none
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
</IfModule>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/x-javascript
</IfModule>
Apache error is here:
J:/wamp/www/site/.htaccess: Invalid command 'AddOutputFilterByType', perhaps misspelled or defined by a module not included in the server configuration, referer: /site/about/
If you are using apache 2.4, you need to change
<IfModule mod_deflate.c>
to
<IfModule mod_filter.c>
as the output filter has been moved to mod_filter. Then you need to make sure you have mod_filter loaded.
i have the following folder structure on my hosting (it is a shared one)
public_html
|
|
|--- website (contains CodeIgniter application)
|--- otherapp (another CodeIgniter application)
|--- moreapp (yet another web application)
What i want to do is that when ever a user type my domain (http://example.com) it should loads the content within the 'website' folder.
While a user type http://otherapp.example.com it should open what ever index.php reside within the 'otherapp' folder.
First i tried this (and saved it in the root folder[public_html]):
Redirect /index.php http://example.com/otherapp/index.php and it pretty much screwed the URL and links.
Then i tried this (a brute copy paste from Joomla htaccess):
## Can be commented out if causes errors, see notes above.
Options +FollowSymLinks
## Mod_rewrite in use.
RewriteEngine On
# Block out any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block out any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL.
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root homepage
RewriteRule .* index.php [F]
##
# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root).
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the request is for something within the component folder,
# or for the site root, or for an extensionless URL, or the
# requested URL ends with one of the listed extensions
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
Within otherapps folder (which is the codeigniter application i have this specific .htaccess)
which:
1. To get rid of index.php ending trail
2. Speed up web page load by doing some caching
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
#
# associate .js with "text/javascript" type (if not present in mime.conf)
#
AddType text/javascript .js
#
# configure mod_expires
#
# URL: http://httpd.apache.org/docs/2.2/mod/mod_expires.html
#
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 seconds"
ExpiresByType image/x-icon "access plus 2692000 seconds"
ExpiresByType image/jpeg "access plus 2692000 seconds"
ExpiresByType image/png "access plus 2692000 seconds"
ExpiresByType image/gif "access plus 2692000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 2692000 seconds"
ExpiresByType text/css "access plus 2692000 seconds"
ExpiresByType text/javascript "access plus 2692000 seconds"
ExpiresByType application/x-javascript "access plus 2692000 seconds"
ExpiresByType text/html "access plus 600 seconds"
ExpiresByType application/xhtml+xml "access plus 600 seconds"
</IfModule>
#
# configure mod_headers
#
# URL: http://httpd.apache.org/docs/2.2/mod/mod_headers.html
#
<IfModule mod_headers.c>
<FilesMatch "\\.(ico|jpe?g|png|gif|swf|css|js)$">
Header set Cache-Control "max-age=2692000, public"
Header set Last-Modified "Mon, 31 May 2014 00:00:00 GMT"
</FilesMatch>
<FilesMatch "\\.(x?html?|php)$">
Header set Cache-Control "max-age=600, private, must-revalidate"
</FilesMatch>
Header set Connection keep-alive
</IfModule>
#Gzip
<ifmodule mod_deflate.c>
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml application/x-javascript application/x-httpd-php
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip
Header append Vary User-Agent env=!dont-vary
</ifmodule>
#End Gzip
The problem that i am facing at the moment is that some links are not redirected properly. I am not sure how to explain the problem (i think it is too random).
Place this rule in root .htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^((?!website/).*)$ website/$1 [NC,L]
RewriteCond %{HTTP_HOST} ^otherapp\.example\.com$ [NC]
RewriteRule ^((?!otherapp/).*)$ otherapp/$1 [NC,L]