Stop .htaccess rules to be carried over - .htaccess

I am fighting on one Domain already quite a while with its .htaccess rules. I have found the rules I needed to redirect all non-existing files and folders and got it to work after i change its position in the .htaccess to top, so that my .htaccess looks now like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ / [R=301,L]
</IfModule>
#Rewrite for non www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/? [R=301,L]
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} acer|alcatel|amoi|android|asus|avantgo|benq|blackberry|blazer|boxee|bravia|cdm-|ce-html|compal|(core|gom|m|vlcmedia|windows-media)player|dlna|docomo|dreambox|elaine|ericsson|fennec|flycast|foobar2000|google\ wireless\ transcoder|googlebot-mobile|googletv|gt-|hbbtv|hiptop|htc|huawei|iemobile|im-|ipad|ipaq|iphone|ipod|iris|itunes|kindle|large|lg(-|\/|_|1|2|3|4|5|6|7|8|9|e|http)|lenovo|levis|maemo|midp|miro|mmp|mot-|mobile|motorola|msn.*tv|mtv|nettv|nexus|nintendo|nokia|opera\ (mobi|mini)|palm|panasonic|pantech|pg-|philips|pixi\/|playstation|plex|plucker|pocket|portalmmm|pre\/|psp|quicktime|qtek|rim|sagem|samsung|sanyo|sch-|screen|sec-sgh|sendo|sfr|sgh-|sharp|sie-|smart(hub|phone|.?tv)|sonyericsson|sph-|sprint|spv|swisscom|symbian|t-mobile|tablet|toshiba|touch|treo|upnp|up.browser|vertu|videoweb|vk-|vodafone|volksbox|wafa|wap|webos|webtv|wii|windows\ (ce|phone)|wml|wonu|xbmc|xbox|xda|xiino|zte|zune [NC]
RewriteRule ^(.*)$ http://www.domain.tld/m/ [L,R=302]
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##
<IfModule mod_deflate.c>
<filesMatch "\.(js|css|html|php|jpg|jpeg)$">
SetOutputFilter DEFLATE
</filesMatch>
</IfModule>
My problem is that my subfolders would need its own redirect rules for non-existing files/folders. I do not want them to be redirected to the root, but rather to their correct index'folder'.
The Site is build like this:
http://www.domain.tld/ <-- Mainsite
http://www.domain.tld/keywordX/1/ <-- Index folder for keyword X
http://www.domain.tld/keywordY/1/ <-- Index folder for keyword Y
http://www.domain.tld/keywordZ/1/ <-- Index folder for keyword Z
After I had added the rules to redirect all non-existing files/folders from root it also redirects my non existing files/folders in the Subfolders to the root too.
I have change the First Part of my .htaccess afterwards in a way i found to exclude directories, but that ended in a redirect error:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(keywordX|keywordY|keywordZ)($|/) - [L]
RewriteRule ^(.*)$ / [R=301,L]
</IfModule>
Any suggestion how i can avoid this behavior?
The following i have tried to add in the htaccess in /keywordX/ folder as also in the /keywordX/1/ folder:
I had found that adding an "RewriteEngine On" would do the trick. But it didn't.
I found that Line 1 RewriteEngine Off and Line 2 RewriteEngine On would work, but it also didn't.
Update 3:
The first time the site is loading properly AND the most redirects for the root are working. All existing folders are NOT redirected (No idea why it is not redirecting them as they are not excluded), but so far kproxy shows me kategoryX/kategoryY/kategoryZ are loading as they should.
It looks like i was with my previous tryouts on the right path, just that my file exclusion was incorrect. But after more and more reading and slowly but steadily getting more angry, i stumbled upon file extension exclusion.
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(images)/ [NC]
RewriteCond %{REQUEST_URI} !\.(xml|txt|css)$
RewriteRule ^.+$ / [R=302,NC,L]
With this bit of Code i was able to redirect all incorrect FOLDER request back to root.
What now is missing, is a redirect for incorrect files (what are the major part of the redirects) ... files like 123_itemname.html, 456_itemname.html and so on.
Is there a way to extend the htaccess code that i am using right now, or do i need to have a complete new approach?
Edit: I have made a lot of editing to the Question as i just couldn't wait and let someone else figure out whats wrong.

Related

New .htaccess breaks site

I'll admit I'm brand brand new to coding. I am trying to help a client who uses Dreamweaver to publish their website on a server at their headquarters. I asked their IT department to add code to their .htaccess file that would help redirect non https to https and force www but also remove the .html extensions. I am pretty sure the code is correct but when they added it, the site broke.
The old .htaccess file had the following code:
/var/www/html/HRT/.htaccess
RedirectMatch 301 ^/here(/.+?)?$ http://go.example.com/here
RedirectMatch 301 ^/HERE(/.+?)?$ http://go.example.com/here
RedirectMatch 301 ^/there(/.+?)?$ http://go.example.com/there
RedirectMatch 301 ^/THERE(/.+?)?$ http://go.example.com/there
I changed the urls for privacy. Just having this worked before. But when I asked them to add the below code, it broke. Not sure even where to start.
# FORCE HTTPS, FORCE WWW and REMOVE HTML #
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]
RewriteRule ^([^/]+)\.html$ $1 [QSA,L]
# EXPIRES CACHING VIA HTACCESS #
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
I should note that during the previous week they added to their http.config file for expiring cache too so I'm not sure that would cause this problem. Just trying to think of all the things they've done before this error.
Thanks in advance.
RewriteRule ^([^/]+)\.html$ $1 [QSA,L]
You can't simply "remove" the .html file extension like that in .htaccess - it will most certainly break your site.
In fact, you can't remove the file extension by editing .htaccess alone. It's a two stage process:
You need to remove the .html extension on all your URLs - in your application. All your internal links need to be updated to omit the .html extension.
You then use .htaccess to internally rewrite the request without an extension, back to the real filesystem path that includes the .html extension. Underneath it all, your filesystem paths have not changed.
For example:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]+)$ $1.html [L]
This assumes that your URLs do not otherwise contain dots (.) - except if they are requesting a file directly (eg. .js, .css, .jpg, etc.)
You will also need to ensure that MultiViews is disabled (if not already) for this to work properly. ie. Include the following at the top of your .htaccess file:
Options -MultiViews
If you are changing an existing URL structure then you'll need to implement an external redirect to physically remove the .html extension from the URL in order to preserve SEO. However, you should only implement this if you have completed step #1 (and #2) above and removed the .html extension on all your internal URLs (otherwise your users will suffer an external redirect on every link when navigating your site, which will be slow and double the requests hitting your server).
For example, the following redirect would need to go before the rewrite (above):
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule (.+)\.html$ /$1 [R=302,L]
The condition that checks against the REDIRECT_STATUS environment variable ensures that we target only direct requests and not the rewritten request.
Note that this is currently a 302 (temporary) redirect. Only change it to a 301 (permanent) redirect once you have confirmed that it works OK - in order to avoid caching issues.
In Summary
# Disable MultiViews
Options -MultiViews
Then add the following below your canonical HTTP to HTTPS and non-www to www redirects:
# Redirect to remove the ".html" extension from direct requests
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule (.+)\.html$ /$1 [R=302,L]
# Internal rewrite to re-append the ".html" extension for the internal request
# NB: Exclude requests for directories
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]+)$ $1.html [L]

Delete the name of the folder that came up in the url domain using htaccess

I'm having trouble with the domain url. When I call my website's url address in the browser, the folder name of the website comes up. I have another website too and that's fine, my other website url address does not show the folder name. I mean like this:
this is an example of my other website and that's fine with not displaying the folder name
And this url of my website that come show the folder name
the difference is quite noticeable instead. I want to make my website url address pure url name that I want without calling the folder name. it is the start page and I want to delete the folder name.
I have tried various scripts but it happens just blank and sometimes error.
this is the last script I tried and it still does not work and url still show the folder name. I have never been like this before.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \ /+(.*)\?redirect=1&?([^\ ]*)
RewriteRule ^ /%1?%2 [L,R]
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 month"
ExpiresDefault "access 1 month"
</IfModule>
# END WordPress
<ifModule mod_headers.c>
<filesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>
<filesMatch "\\.(css)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>
<filesMatch "\\.(js)$">
Header set Cache-Control "max-age=216000, private"
</filesMatch>
<filesMatch "\\.(xml|txt)$">
Header set Cache-Control "max-age=216000, public, must-revalidate"
</filesMatch>
<filesMatch "\\.(html|htm|php)$">
Header set Cache-Control "max-age=1, private, must-revalidate"
</filesMatch>
</ifModule>
<IfModule mod_headers.c>
<FilesMatch ".(js|css|xml|gz|html)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>
<Files 403.shtml>
order allow,deny
allow from all
</Files>
deny from 192.168.1.22
<IfModule mime_module>
AddType application/x-httpd-ea-php56 .php .php5 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
it's the htaccess script inside the public_html folder. And this script is in the folder id or folder of my website whose url is problematic :
## No directory listings
<IfModule autoindex>
IndexIgnore *
</IfModule>
## Can be commented out if causes errors, see notes above.
Options +FollowSymlinks
Options -Indexes
## Mod_rewrite in use.
RewriteEngine On
## Begin - Rewrite rules to block out some common exploits.
# If you experience problems on your site then comment out the operations listed
# below by adding a # to the beginning of the line.
# This attempts to block the most common type of exploit `attempts` on Joomla!
#
# Block any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block 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 home page
RewriteRule .* index.php [F]
#
## End - Rewrite rules to block out some common exploits.
# RewriteBase
RewriteCond %{THE_REQUEST} \ /+(.*)\?redirect=1&?([^\ ]*)
RewriteRule ^ /%1?%2 [L,R]
## Begin - Joomla! core SEF Section.
#
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 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]
#
## End - Joomla! core SEF Section.
It's not working at all and I'm also confused whether I put the url manipulation script correctly. Anyone can help me ??

Redirect a page from one page to another page without changing the URL using htaccess in Joomla

Is there any way to Redirect a page from one page to another page without changing the URL using htaccess in joomla?
I want to load URL site.com/page1 load content site.com/page2. I tried to do this with the following command:
RewriteRule ^page1$ /page2 [L]
Or
RewriteRule ^page1$ /page2
But nothing has changed.
When it tried to do not Joomla then works fine
Is there any way to Redirect a page from one page to another page without changing the URL using htaccess in joomla?
I want to load URL site.com/page1 load content site.com/page2. I tried to do this with the following command:
RewriteRule ^page1$ /page2 [L]
Or
RewriteRule ^page1$ /page2
But nothing has changed.
When it tried to do not Joomla then works fine.
here is my htaccess file
##
# #package Joomla
# #copyright Copyright (C) 2005 - 2014 Open Source Matters. All rights reserved.
# #license GNU General Public License version 2 or later; see LICENSE.txt
##
##
# READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE!
#
# The line just below this section: 'Options +FollowSymLinks' may cause problems
# with some server configurations. It is required for use of mod_rewrite, but may already
# be set by your server administrator in a way that dissallows changing it in
# your .htaccess file. If using it causes your server to error out, comment it out (add # to
# beginning of line), reload your site in your browser and test your sef url's. If they work,
# it has been set by your server administrator and you do not need it set here.
##
## Can be commented out if causes errors, see notes above.
Options +FollowSymLinks
## Mod_rewrite in use.
RewriteEngine On
## Begin - Rewrite rules to block out some common exploits.
# If you experience problems on your site block out the operations listed below
# This attempts to block the most common type of exploit `attempts` to Joomla!
#
# 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]
#
## End - Rewrite rules to block out some common exploits.
## Begin - Custom redirects
#
# If you need to redirect some pages, or set a canonical non-www to
# www redirect (or vice versa), place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.
#
## End - Custom redirects
##
# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root).
##
RewriteBase /
RewriteCond %{HTTP_HOST} (.*)
RewriteCond %{REQUEST_URI} !^/administrator
RewriteCond %{REQUEST_URI} /$ [NC]
RewriteRule ^(.*)(/)$ $1 [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ / [R=301,L]
RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [L]
RewriteRule ^page1$ /page2 [L]
## Begin - Joomla! core SEF Section.
#
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]
#
## End - Joomla! core SEF Section.
RewriteCond %{REQUEST_URI} ^/sitemap.xml
RewriteRule .* /index.php?option=com_xmap&id=1&view=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 mod_deflate.c>
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/css
<IfModule mod_setenvif.c>
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access 7 days"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType text/javascript "access plus 1 year"
ExpiresByType text/css "access plus 1 year"
ExpiresByType text/html "access plus 7 day"
ExpiresByType text/x-javascript "access 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/x-icon "access 1 year"
ExpiresByType application/x-shockwave-flash "access 1 year"
</IfModule>
You can do it as follows
RewriteEngine on
RewriteRule ^(page2)$ /page1 [L]
Also you mention Joomla!, so It already has as RewriteEngine on, then just insert the following code right below it, before the Joomla!'s own rewrite rules kick in.
RewriteRule ^(page2)$ /page1 [L]

Htaccess redirect happens different for www and non www

I have redirected all non www to www url using the following
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Next ,
The final url for categories required is :
http://www.slidecorner.com/category/Design
I have used this for achieving this
RewriteRule ^/?category/(.*) category.php?ctitle=$1
This also works, but when i check this url in any redirect checking websites , the "www" version of url is perfect, but "non www" url internally redirects to :
http://www.slidecorner.com/category.php/Design?ctitle=Design
Is this good for a search engine ? Please advise
Update : Tried [L] flag also , and rewritebase is already there. Attached full htaccess for reference
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^docs$ docs.php
RewriteRule ^category$ category.php
RewriteRule ^categories$ categories.php
RewriteRule ^members$ members.php
RewriteRule ^upload$ upload.php
RewriteRule ^search$ search.php
RewriteRule ^account$ account.php
RewriteRule ^logout$ logout.php
RewriteRule ^login$ login.php
RewriteRule ^signup$ signup.php
RewriteRule ^feeds$ feeds.php
RewriteRule ^mydocs$ mydocs.php
RewriteRule ^myfav$ myfavoritedocs.php
RewriteRule ^doc/(.*)/(.*) viewdoc.php?did=$1&title=$2
RewriteRule ^syndicate/docs/(.*)/(.*) syndicatedocs.php?filter=$1&title=$2
RewriteRule ^download/doc/(.*)/(.*) downloaddoc.php?DID=$1&title=$2
RewriteRule ^resetpassword/(.*) resetpassword.php?code=$1
RewriteRule ^confirmemail/(.*) confirmemail.php?code=$1
RewriteRule ^resendconfirmation/(.*) resendconfirmation.php?userid=$1
RewriteRule ^members/profile/(.*)/(.*) memberprofile.php?pid=$1&username=$2
RewriteRule ^/?category/(.*) category.php?ctitle=$1 [L]
# to hide jpg images
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?slidecorner.com[NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?slidecorner.*$ [NC]
RewriteRule \.(jpeg|jpg)$ - [F]
# to hide jpg images
# for sending compressed data to load faster
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html
# for sending compressed data to load faster
</IfModule>
# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymLinks
Options +SymLinksIfOwnerMatch
#non www redirect ,since the above doesnt redirect
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##
<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>
Options -Indexes
Update : I found the issue is due to this code
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
I removed that and the url is fine . Also the non www to www redirection is completely stopped because i removed that
Is there anything wrong with the above code ?
The order of directives (within modules) matters in .htaccess. Whilst your question suggests you are performing the canonical www redirect first, you actually have this after the internal rewrites in your .htaccess files and this is certainly a problem in this case. (Although the exact output you are getting from the "checking tool/website" would seem to be a fault of the "tool" IMO.)
Generally, you should always have external redirects before internal rewrites.
With the internal rewrite first you ending up losing your "pretty URL". What actually happens when you access the non-canonical (non-www) URL http://example.com/category/Design is:
Internal rewrite to:
/category.php?ctitle=Design
External redirect to:
http://www.example.com/category.php?ctitle=Design
It is important to realise that the L (last) flag only halts the current processing of the rule set. If an internal or external redirect has occurred then process starts again!

Combine the .htaccess files for silverstripe and squeezr

I am trying to combine two .htaccess files into one:
https://github.com/silverstripe/silverstripe-installer/blob/3.1/.htaccess
AND
https://github.com/jkphl/squeezr/blob/master/.htaccess
I also want to exclude the CMS from any squeezr rules (i.e. links to http://www.mysite.co.nz/admin/.... should not run via squeezr.
Is it sufficient to basically combine the two .htaccess files and write the final redirection rule for silverstripe as follows:
RewriteRule (?!^squeezr|admin)^.*$ framework/main.php?url=$1 [L,QSA,NC]
Please let me know if you need more information in this question and I will add.
You should be able to just combine the 2. There doesn't seem any conflict
https://gist.github.com/24b48c12d82c73e60a37
EDIT:
In your question you also mention that you want to exclude the cms from sqeezer, the idea makes sense, however, the RewriteRule you have posted does not at all, in fact I would be surprised if that did not throw an error.
The only thing the above rule would do (if it would work), would be to exclude squeezr files from being rewritten to framework, but that would never happen anyway, because the RewriteConds before would already deny that (SilverStripe does not rewrite existing files).
so what you need to do is actually add a RewriteCond to the 2 squeezr rules, to tell them not to use cms and framework.
I believe adding the 2 following conditions (right before the squeezr rules) would do that:
RewriteCond %{REQUEST_URI} !cms # exclude the silverstripe cms
RewriteCond %{REQUEST_URI} !framework # exclude the silverstripe framework which is by
(you can also view it as diff for the gist here: https://gist.github.com/Zauberfisch/d681474df67ced83ec1f/revisions)
the full config file:
ErrorDocument 404 /assets/error-404.html
ErrorDocument 500 /assets/error-500.html
<Files *.ss>
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Files>
<Files web.config>
Order deny,allow
Deny from all
</Files>
<Files ~ "\.ya?ml$">
Order allow,deny
Deny from all
</Files>
<IfModule mod_rewrite.c>
Options +FollowSymlinks
# Start the rewrite engine
RewriteEngine On
RewriteBase /
# REDIRECT ANY DIRECT IMAGE REQUEST TO A CACHED VERSION
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{ENV:REDIRECT_BREAKPOINT} !\d+px
RewriteCond %{QUERY_STRING} !^([^&]*&)*squeezr=(0|false|no)
RewriteCond %{HTTP_COOKIE} squeezr.images=(\d+px) [NC]
RewriteCond %{REQUEST_URI} !cms # exclude the silverstripe cms
RewriteCond %{REQUEST_URI} !framework # exclude the silverstripe framework which is by the cms
RewriteRule ^(.+)(\.(?:jpe?g|gif|png))$ squeezr/cache/$1-%1$2 [NC,E=BREAKPOINT:%1,L]
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Please make sure that you set this path ^^^ to the squeezr root directory that is also specified
# for the SQUEEZR_ROOT constant in the common engine configuration (SQUEEZR_ROOT/conf/common.php). If you
# apply the default setup for squeezr (i.e. put everything into a directory named "squeezr" under your
# website's document root), then you shouldn't have to change anything.
#############################################################################################################
# REDIRECT ANY DIRECT CSS REQUEST TO A CACHED VERSION
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{ENV:REDIRECT_BREAKPOINT} !\d+px
RewriteCond %{QUERY_STRING} !^([^&]*&)*squeezr=(0|false|no)
RewriteCond %{HTTP_COOKIE} squeezr.css=(\d+x\d+#\d+(?:\.\d+)?) [NC]
RewriteCond %{REQUEST_URI} !cms # exclude the silverstripe cms
RewriteCond %{REQUEST_URI} !framework # exclude the silverstripe framework which is by the cms
RewriteRule ^(.+)\.css$ squeezr/cache/$1-%1.css [NC,E=BREAKPOINT:%1,L]
# ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# See above for hints on ^^^ this path.
#############################################################################################################
### SILVERSTRIPE START ###
RewriteRule ^vendor(/|$) - [F,L,NC]
RewriteRule silverstripe-cache(/|$) - [F,L,NC]
RewriteRule composer\.(json|lock) - [F,L,NC]
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.php$
RewriteRule .* framework/main.php?url=%1 [QSA]
RewriteCond %{REQUEST_URI} ^(.*)/framework/main.php$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . %1/install.php? [R,L]
### SILVERSTRIPE END ###
</IfModule>
#############################################################################################################
# Additional stuff for improving your website's delivery performance
#############################################################################################################
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css text/javascript text/json text/x-json text/x-json-stream application/x-javascript application/json application/x-json application/x-json-stream application/.*xml.* multipart/x-json-stream multipart/x-mixed-replace image/svg+xml
</IfModule>
<IfModule mod_expires.c>
ExpiresActive on
# Images
ExpiresByType image/gif "access plus 35 days"
ExpiresByType image/png "access plus 35 days"
ExpiresByType image/jpg "access plus 35 days"
ExpiresByType image/jpeg "access plus 35 days"
# Text based files
ExpiresByType text/css "access plus 35 days"
ExpiresByType text/xml "access plus 35 days"
ExpiresByType text/javascript "access plus 35 days"
ExpiresByType application/x-shockwave-flash "access plus 35 days"
# Default expiration
ExpiresDefault "access plus 1 days"
</IfModule>

Resources