Resizing image on the fly - .htaccess

This is my .htaccess. All is working fine. Except there is a problem with this part:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule pic/(.*)--(\d+)*.(jpe?g|JPE?G|gif|GIF|png|PNG)?$ index.php/image/getinsize/?p=pic/$1\.$3&s=$2 [QSL,NS,L]
This creates resized image on the fly for example from:
/pic/posts/2015-12/43242/gals/picture.jpg
and stores it as:
/pic/posts/2015-12/43242/gals/picture--900.jpg
Image is saved on hdd and served by Apache. Problem is when next time the same image is requested, instead of serving already resized image, server is resizing and overiding it. Any idea why the !-f doesn't work?
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule static\/([^/]+)\/([^/]+)$ static/$1/$2 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule static/help/bg\/(.*)\/?$ /static/help/bg/item.php?l=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (lng_[^/]+)\/([^/]+)\/([^/]+)\/?$ /index.php/$2/$3?lng=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule news\/([0-9]+)\/([^/]+)\/([0-9]+)\/?$ /index.php/posts/post/?id=$1&pagenum=$3 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule news\/([0-9]+)\/([^/]+)\/?$ /index.php/posts/post/?id=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule polls\/([0-9]+)\/([^/]+)\/?$ /index.php/polls/poll/?id=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule pic/(.*)--(\d+)*.(jpe?g|JPE?G|gif|GIF|png|PNG)?$ index.php/image/getinsize/?p=pic/$1\.$3&s=$2 [QSL,NS,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule pic\/(.*)--(pdf)(\d+)*\.(jpe?g|JPE?G|gif|GIF|png|PNG)?$ /index.php/image/getinsizefrompdf/?p=pic/$1\.$4&s=$3&f=$2 [QSD,NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ([^/]+)\/([^/]+)\/([^/]+)\/?$ /index.php/$1/$2/$3 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (lng_[^/]+)\/([^/]+)\/([^/]+)\/([^/]+)\/?$ /index.php/$2/$3/$4?lng=$1 [QSA,L]
RewriteRule ^feed/?$ /index.php/index/rss [QSA,L]
RewriteRule ^sitemap\.xml$ /index.php/index/sitemapxml [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ([^/]+)\/([0-9]+)\/?$ /index.php/pages/page/?url=$1&pagenum=$2 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ([^/]+)\/([^/]+)\/?$ /index.php/pages/page/?lang=$1&url=$2 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ([^/]+)\/([^/]+)\/?$ /index.php/$1/$2 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ([^/]+)\/?$ /index.php/pages/page/?url=$1 [QSA,L]

Related

How to separate two variables with a hyphen using htaccess

I'm trying to do some url like that: domain.com/category-subcategory.
If I go to domain.com/category Its work, but if I trying to go to domain.com/category-subcategory it is not working..
this is my code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ category.php?category=$1 [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)-([^/]+)/$ category.php?category=$1&subcategory=$2 [L,NC]
How can I fix it? Thanks
Edit: I fixed it! here is the code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)-([^/]+)$ category.php?category=$1&subcategory=$2 [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ category.php?category=$1 [L,NC]
I was only need to remove the slash before the $ at the end. Thanks for everyone!
Try with below,
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)-([^/]+)$ category.php?category=$1&subcategory=$2 [L,NC]

rewriterule dynamic with sub

I can't fix this issue. I'm trying to get rewrite rules to work with dynamic urls like:
http://example.com/[CATEGORY]/[PAGE]/[OPTIONS]
or
http://example.com/[PAGE]
This is my .htaccess
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} ^(.*[^/])
RewriteRule ^(.*[^/]) /index.php?url=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} ^(.*[^/])\/^(.*[^/])
RewriteRule ^(.*[^/])\/^(.*[^/]) /index.php?url=$1/$2 [QSA,L]
The first rewriterule is working, but the second isn't. Also is this not clean.
Anyone who knows this?

Frog CMS htaccess diagnosis

I have a issue with Frog CMS, its the first time I use this CMS, is a client that uses this.
Scenario: I modified 1 redirection using a plugin called "Redirector" that destroyed the whole site!
Luckly, I found an htaccess from some months ago, that allows the site to work, but the redirections none of them works, the site works, but not the redirections, the main url rewriting for the site seems to be Ok, but the 301 redirects I need, dont work.
I cant figure out why this is happening, why this redirections dont work correctly, they dont conflict, but they dont do nothing! Can you advice on this ? Im looking forward uderstanding more about url rewritting and htaccess.
I cant use the plugin to generate redirections, because it destroyed the whole site. If there is a way to "reset" the url rewritting in this CMS it would be good, but I dont have cooperation form the developers of the site...
I appreciate any help to understand better what is wrong , why all the
RewriteRule ^site/services/immigration/ /services/immigration.html [L,R=301]
dont work!
### CMS-Generated Update August 1, 2013, 1:45 pm ###
#
# Setting Frog requirements
#
AddType text/x-component .htc
AddType video/ogg .ogm
AddType video/ogg .ogv
AddType video/ogg .ogg
AddType video/webm .webm
AddType video/mp4 .mp4
AddType video/x-m4v .m4v
AddType audio/webm .weba
AddDefaultCharset UTF-8
Options -Indexes -MultiViews +FollowSymLinks
DirectoryIndex index.html index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !.local$ [NC]
RewriteCond %{HTTP_HOST} !.local$ [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^install/index.html$ install/index.php?rewrite=1 [L,QSA]
RewriteRule ^install/index.php$ install/index.php?rewrite=1 [L,QSA]
RewriteRule ^install/$ install/index.php?rewrite=1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^admin(.*)$ admin/index.php?$1 [L,QSA]
RewriteCond %{DOCUMENT_ROOT}/cache/index.html -f
RewriteRule ^$ /cache/index.html [L,QSA]
RewriteCond %{REQUEST_METHOD} ^GET$
RewriteCond %{DOCUMENT_ROOT}/cache/%{REQUEST_URI} -f
RewriteRule ^(.*)$ /cache/$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^download/(.*)$ /downloads.php?THISPAGE=download.html&media=pdf&filename=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^private/(.*)$ /private.html?THISPAGE=private.html&userfile=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^mobile/search/(.*)$ mobile.html?THISPAGE=search.html&media=mobile&search=$1 [L,QSA]
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME} !-l
#RewriteRule ^mobile/(.*)/process.html$ mobile.html?THISPAGE=$1&media=mobile&return=process [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^mobile/(.*)/success.html$ mobile.html?THISPAGE=$1&media=mobile&return=success [L,QSA]
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^standard/search/(.*)$ standard.html?THISPAGE=search.html&media=standard&search=$1 [L,QSA]
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME} !-l
#RewriteRule ^standard/(.*)/process.html$ standard.html?THISPAGE=$1&media=standard&return=process [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^standard/(.*)/success.html$ standard.html?THISPAGE=$1&media=standard&return=success [L,QSA]
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME} !-l
#RewriteRule ^(.*)/process.html$ contact.html?THISPAGE=$1&return=process [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)/success.html$ contact.html?THISPAGE=$1&return=success [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^search/(.*)$ index.php?THISPAGE=search.html&search=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^proposal.html$ index.php?THISPAGE=$1&media=proposal [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^contrast/search/(.*)$ contrast.html?THISPAGE=search.html&search=$1&media=contrast [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^print/search/(.*)$ print.html?THISPAGE=search.html&search=$1&media=print [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^mobile/(.*)$ mobile.html?THISPAGE=$1&media=mobile [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^standard/(.*)$ standard.html?THISPAGE=$1&media=standard [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^print/(.*)$ print.html?THISPAGE=$1&media=print [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^pdf/(.*)$ pdf.html?THISPAGE=$1&media=pdf [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^proposal/(.*)$ proposal.html?THISPAGE=$1&media=proposal [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^flash/(.*)$ flash.html?THISPAGE=$1&media=flash [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^contrast/(.*)$ contrast.html?THISPAGE=$1&media=contrast [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?THISPAGE=$1 [L,QSA]
RewriteRule ^/site/aboutus/(.*)$ /$1 [L,R=301]
RewriteRule ^site/aboutus/ / [L,R=301]
RewriteRule ^pages/about_us.htm /about.html [L,R=301]
RewriteRule ^site/contact/ /contact.html [L,R=301]
RewriteRule ^site/library/ /resources.html [L,R=301]
RewriteRule ^site/services/ /services.html [L,R=301]
RewriteRule ^site/services/alternative_dispute_resolution/ /services/alternative-dispute-resolution.html [L,R=301]
RewriteRule ^site/services/business_visas/ /services/business-visas.html [L,R=301]
RewriteRule ^site/services/civil_comm_litigation/ /services/civil-commercial-litigation-copy.html [L,R=301]
RewriteRule ^site/services/clinical_negligence/ /services/clinical-negligence.html [L,R=301]
RewriteRule ^site/services/conveyancing/commercial/ /services/commercial-conveyancing.html [L,R=301]
RewriteRule ^site/services/company_law/ /services/company-law.html [L,R=301]
RewriteRule ^site/services/criminal_law/ /services/criminal-law.html [L,R=301]
RewriteRule ^site/services/divorce_matrimonial/ /services/divorce-matrimonial.html [L,R=301]
RewriteRule ^site/services/employment_law/ /services/employment-law.html [L,R=301]
RewriteRule ^site/services/human_rights/ /services/human-rights-issues.html [L,R=301]
RewriteRule ^site/services/immigration/ /services/immigration.html [L,R=301]
RewriteRule ^site/services/leases_tenancy/ /services/leases-tenancy-agreements.html [L,R=301]
RewriteRule ^site/services/injury_medical_negligence/ /services/personal-injury-medical-negligence.html [L,R=301]
RewriteRule ^site/services/pro_bono/ /services/pro-bono.html [L,R=301]
RewriteRule ^site/services/conveyancing/ /services/residential-conveyancing.html [L,R=301]
RewriteRule ^site/services/conveyancing/residential/ /services/residential-conveyancing.html [L,R=301]
RewriteRule ^site/services/wills_trusts_probates/ /services/wills-trusts-probates.html [L,R=301]
RewriteRule ^site/people/ /team.html [L,R=301]
</IfModule>
It's because you have this rule before all of your other services redirect rules:
RewriteRule ^site/services/ /services.html [L,R=301]
This is saying, "anything that starts with /site/services/ gets redirected to /services.html". So, when you have a rule like:
RewriteRule ^site/services/company_law/ /services/company-law.html [L,R=301]
after it, the second rule will never get executed, since the second rule matches /site/services/company_law, which starts with /site/services/, thus matching the first rule. You need to re-order all of your rules so that the more general rule is at the end. Just put the
RewriteRule ^site/services/ /services.html [L,R=301]
rule at the very bottom.

Pretty url index page

I only got the first pretty url working. I don't get the 2nd and 3rd working, they just show a messed up page (Styles not loaded) + it show wrong page
Here is my code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?tab=$1 [NC]
RewriteRule ^/ucp(.*)$ index.php?ucp&tab=$1 [NC]
RewriteRule ^/ucp(.*)$ index.php?ucp [NC,L]
.
Possible urls:
http://subdomain.domain.com/path2files/index.php?&tab=str
http://subdomain.domain.com/path2files/index.php?ucp
http://subdomain.domain.com/path2files/index.php?ucp&tab=str
How they should look like:
http://subdomain.domain.com/path2files/str
http://subdomain.domain.com/path2files/ucp
http://subdomain.domain.com/path2files/ucp/str
Try this:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /path2files/index\.php\?ucp&tab=(.*)\ HTTP
RewriteRule ^ /path2files/ucp/%2\? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^path2files/ucp/(.*)$ /path2files/index.php?ucp&tab=$1 [L]
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /path2files/index\.php\?ucp\ HTTP
RewriteRule ^ /path2files/ucp\? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^path2files/ucp$ /path2files/index.php?ucp [L]
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /path2files/index\.php\?&tab=(.*)\ HTTP
RewriteRule ^ /path2files/%2\? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} !^/ucp
RewriteRule ^path2files/(.*)$ /path2files/index.php?&tab=$1 [L]

.htaccess if directive

in .htaccess I have something like this:
RewriteCond %{REQUEST_URI} (\/out\/pictures\/)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (\.jpg|\.gif|\.png)$ core/utils/getimg.php
I want to change it to
RewriteCond %{REQUEST_URI} (\/out\/pictures\/)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
if url == www.mysite.com {
RewriteRule (\.jpg|\.gif|\.png)$ core/utils/getimg.php
} else {
RewriteRule (\.jpg|\.gif|\.png)$ core/utils/getimg1.php
}
Is it possible in some way?
Unfortunately I think it's necessary to split this out into two:
RewriteCond %{REQUEST_URI} (\/out\/pictures\/)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^www\.mysite\.com
RewriteRule (\.jpg|\.gif|\.png)$ core/utils/getimg.php
RewriteCond %{REQUEST_URI} (\/out\/pictures\/)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^www\.mysite\.com
RewriteRule (\.jpg|\.gif|\.png)$ core/utils/getimg1.php
I've not tested this - so your mileage may vary!

Resources