I'm trying to set some htaccess rules for a specific Kohana controller. Basically its to do with form uploads. The majority of the site doesn't want to allow for large uploads so the php.ini will remain with the recommended settings.
However in one place a large file upload is required. I have the following options to add in my root .htaccess:
php_value max_input_time 60000
php_value post_max_size "1GB"
php_value upload_max_filesize "1GB"
php_value memory_limit "128MB"
But I don't know what to do to make it apply just for one controller (i.e. http://www.mysite.com/massiveupload).
Any help would be appreciated.
There's also another solution. Again thanks to #LazyOne for the tip. This one is much neater, but it requires updating the Apache config directly (so you cannot deploy it on a shared hosting).
All you have to do is add this to your httpd.conf or vhosts.conf (inside <Directory> or <VirtualHost> as per Apache Docs).
<LocationMatch /massiveupload>
php_flag max_input_time 60000
php_value post_max_size 1024M
php_value upload_max_filesize 1024M
php_value memory_limit 128M
</LocationMatch>
Restart your server and it should just work!
Note, that although LocationMatch parses the /massiveupload as a regular expression, we cannot use ^/massiveupload (note the ^ char to match beginning of the string). This is because it will fail if you use a ModRewrite (which changes the final request url internally).
Note, you shouldn't make upload_max_filesize and post_max_size the exact same size, because if you upload a file that just reaches the upload_max_filesize limit, any other post data will cause it to exceed the post_max_size and the form submission will fail.
What #LazyOne suggested is fairly easy to accomplish actually.
Consider this folder structure (only listing the most important files/folders):
application/
bootstrap.php
lib/
kohana-3.0.8/
modules/
system/
public_html/ <----- this is your DOCUMENT_ROOT
.htaccess
index.php
And consider you're using default Kohana's .htaccess:
RewriteEngine On
RewriteBase /
<Files .*>
Order Deny,Allow
Deny From All
</Files>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT]
Now create an upload/ folder in your public_html/.
Copy both .htaccess and index.php from your DOCUMENT_ROOT to the upload/ folder.
Edit your upload/.htaccess: (only new changed lines displayed)
php_flag max_input_time 86400
php_value post_max_size 1536M
php_value upload_max_filesize 1024M
RewriteEngine On
RewriteBase /upload/
...
RewriteRule .* index.php/upload/$0 [PT]
Edit your upload/index.php and update all paths ($application, $modules, $system).
You can download the whole tested package
Create an upload controller.
Additionally you could split index.php into two parts (cut after defining the paths) so you don't duplicate the whole file.
Setup like this worked just well for me and you can download my test application from here: http://d.pr/ioYk
Related
SCENERIO:
Recently I migrated CodeIgniter from 2.4 to 3.1.9 along with PHP from 5.2 to 7.2. Also, created a new httpd.conf file in apache. When I go to the site's URL, it loads the default page fine and I can browse to default or root
pages without any issues. There are multiple sub-domains that are mapped in routes.php to the main httpd root directory /var/www/html. These sub-domains have a symbolic link to /var/www/html, and within assets folder are
the customization files for each sub-domains.
Root HTTPD directory "/var/www/html" structure
application assets
test1 -> /var/www/html
test2 -> /var/www/html
index.php
system
URL is set as follows in config.php.
$config['base_url'] = 'https://example.com/';
Below is my entry in routes.php:
$route['default_controller'] = "home";
$route['404_override'] = '';
$route['home'] = "home";
$route['select-product'] = "home/select-product";
$route['test1/select-product'] = "home/select-product";
$route['test2/select-product'] = "home/select-product";
Please check the below image for httpd directory config:
enter image description here
PROBLEM:
When I browse to https://example.com/ it loads everything correctly.
When I go to https://example.com/test1 ==> First page loads correctly. But when I press next, the second page defaults back to 'https://example.com/';. Somehow, it looses /test1 from the browser.
Not sure if this is caused by CodeIgniter URL routing issue or something to do with httpd.conf file of Apache. The same "routes.php" file was working fine on the old server.
The routing/pagination seems to have broken after I set $config['base_url'] = 'https://example.com/';. If left empty, it takes a while for the site to load, and when it does the forms and images are not loaded correctly.
I have spent lots of hours trying to figure out the problem. I am hoping someone genius out there will be able to show be in the right direction.
Thank you.
I had this problem when I upgraded to PHP 7.2, the best solution is ,
for things to work in CI with PHP7.2,
Find and comment out(or remove) the following code from sessions.php (system/libraries/session/session.php) and place it in your index.php at the top.
session_start();
ini_set('session.use_trans_sid', 0);
ini_set('session.use_strict_mode', 1);
ini_set('session.use_cookies', 1);
ini_set('session.use_only_cookies', 1);
ini_set('session.hash_function', 1); ini_set('session.hash_bits_per_character',4);
and for .htaccess, use this
DirectoryIndex index.php
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|.well-known|images|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1
set your uri protocol to AUTO
$config['uri_protocol'] = 'AUTO';
$config['index_page'] = '';
I have a site with two different languages(tr and en). These are in two different folder(tr and en) and each has their own index.html. I want to open tr's index.html at the beginning. My configaration so far;
<VirtualHost #ip-address#:80>
*
*
*
DocumentRoot #path-to-directory#
*
*
*
</VirtualHost>
I tried to add
DirectoryIndex tr/index.html
it did not work.
I tried
DocumentRoot #path-to-directory#/tr
but I could not acces
http://<site-name>/en/index.html
How can I do that? I have tried redirect but it did not work as well.
I am not sure if you are able to force the browser to show the default page, as that sort of defeats it's purpose. The best idea I could think of would be to leave the default as index.html, and use mod_rewrite to direct index.html to app.php.
This should work for the default index ( www.domain.com) and show desired url in browser ( www.domain.com/app.php )
<VirtualHost *:80>
ServerName *.mysite.co.uk
DocumentRoot "/var/www/html/mysite/web/"
DirectoryIndex index.html
RewriteEngine on
RewriteRule ^index\.html$ app.php$1 [L,R=301]
</VirtualHost>
I am trying to open URL of article from Facebook page on my website but the problem is every time error 404 is raised although the article is exists .
After searching I find that there is problem in .htaccess codes and I need help in this.
The problem :
URL : like from facebook page
Website : worked like Real link
As you can see there different between this two links.
The part is added "component/content/" and without the another language prefix "ar".
Some Details :
This is my .htaccess file :
> ##
# #package Joomla
# #copyright Copyright (C) 2005 - 2012 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 /
## 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]
#
# Forward to sitemap
Redirect /sitemap.xml http://www.businesstendersmag.com/ar/?option=com_xmap&view=xml&tmpl=component&id=3
## End - Joomla! core SEF Section.
That's all! Any help will be appreciated.
How do you generate URLs that are posted to Facebook?
Are you generating URLs like this?
// require com_content router.
require_once (JPATH_SITE.'/components/com_content/helpers/route.php');
// generate link.
$link = JURI::root() . substr( JRoute::_( ContentHelperRoute::getArticleRoute( $article->slug, $article->categorySlug ) ), strlen(JURI::base(true)) + 1);
// Where $article->slug & $article->categorySlug are fetched from database.
I am new to Ez Publish, I would like to make the default Rest API working as a first step and next developing my own Rest API extension for mobile communication purpose but I am blocked at the first one.
when I try to get the result from "www.mydomain.com/api/ezp/content/node/2/list" I get "{"error_message":"Not Found"}"
configurations are done:
setting/override/site.ini.append.php
[ExtensionSettings]
ActiveExtensions[]
ActiveExtensions[]=ezprestapiprovider
...
extension/ezprestapiprovider/settings/rest.ini.append.php
<?php /* #?ini charset="utf-8"?
[ApiProvider]
ProviderClass[ezp]=ezpRestApiProvider
[Authentication]
RequireAuthentication=disabled
*/ ?>
.htaccess
DirectoryIndex index.php
RewriteEngine On
RewriteRule api index_rest.php [L]
RewriteRule ^index_rest\.php - [L]
...
I apologize for my English.
Edit1: Ez Publish version 4.5
Edit2: It seems to be a problem of RewirteRule, when I change "www.mydomain.com/api/ezp/content/node/2/list" to "www.mydomain.com/index_rest.php/api/ezp/content/node/2/list" it works , how can I fix that ?
Edit3:
I tried all rewriterules below, still not working except the last one.
# RewriteRule ^/api/ /index_rest.php [L]
# RewriteRule ^api/(.*) /index_rest.php/$1 [R=302,NC]
# RewriteRule ^/api/(.*) /index_rest.php/api/$1 [NC,L]
RewriteRule api index_rest.php [L]
But it seems to create conflit when I try to add new extension...
I added a new extension and when I try to access to it I got an error on the log file:
Unexpected error, the message was : The API provider 'mobile' could not be found. in mydomaine.com\kernel\private\rest\classes\rest_provider.php on line 37
Try replacing those rewriterules with the one specified by eZ
RewriteRule ^/api/ /index_rest\.php [L]
This is listed here for version 4.5: http://doc.ez.no/eZ-Publish/Technical-manual/4.5/Installation/Virtual-host-setup
I just regenerate autoload and it's working now. I use cmd line to do it (regenerating autoload with admin module does not work for me).
after installing digitalus i created the following rule (.htaccess ) file in the root directory
<VirtualHost *:80>
ServerName ecn.local
DocumentRoot /home/speshu/Development/ecn
SetEnv APPLICATION_ENV tinsae
<Directory /home/speshu/Development/ecn>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
and put 127.0.0.1 ecn.local in /etc/hosts
but when i type http://ecn.local/scripts or http://etc.local/library or some existing folder in the document root rather than displaying a not found (404 message ) it lists all the folders in there how can i restrict this
in may earlier projects i remember having such restrictions on zend-framework what is the problem with digitalus since it's built on the same framework ..............
with out modifying in the digitalus
just add Options -Indexes to your wanted folder and it will hide the files (aka 'forbidden message ') like :
Forbidden
You don't have permission to access /library on this server.
for example , if you need to hide the library folder
just create .htaccess file inside of it and write down Options -Indexes
and it will do the job :)