Set the location of the tempdir - .htaccess

It is probarly pretty simple, but i cant find an solution.
How can i set the temp dir for file uploads.
What i want is change the location to www.mydomain.com/temporary
what i have tryd in .htaccess
php_value upload_tmp_dir "/home/mydomain.com/public_html/temporary/"
and without the last slash.
php_value upload_tmp_dir "/home/mydomain.com/public_html/temporary"
Does some one know if it is done by .htaccess and how?

According to the PHP manual, upload_tmp_dir can be changed only in php.in, not on a per-directory basis:
upload_tmp_dir NULL PHP_INI_SYSTEM
You'd have to have root access to the server to change that.

Related

execute script when directory listing by .htaccess

I have a http server (apache HTTPD v2.4) where directory listing is enabled. I configured it to use the 'fancy-index' from https://github.com/Vestride/fancy-index, and works great. However, its searching function didn't give what I was looking for.
I'd like to configure the webserver such that if I goto http://mywebserver.com/someDir/*?list, it will return a list of all the files in someDir in a "file, filesize" format.
Or, if I goto http://mywebserver.com/someDir/essay2020*.txt?list , I'll get a custom list of all essay2020*.txt files. Or some form of a simple regex: say "essay2020[0-2]*.txt".
I can write a php/perl/python script that can read a directory and return the 'file, filesize' list. But how do I configure the .htaccess to call this script? Do I have to muck around with 'RewriteRule'? or something special?
As an added note, I'm not limited to modifying .htaccess only. If I can do all of this by modifying the httpd.conf, I'm open to that suggestion too.
Thanks.
The answer in Comments by CBroe did it. By just modifying the apache2.conf file to add:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^list$
RewriteRule .* /search.php?path=%{REQUEST_URI}
within my <VirtualHost>, I'm now able to forward everything to search.php, where there I can parse and do what needs to be done. All w/o revealing search.php's existence. Thanks.

htaccess hide url ?code= and read it from php file

i want a change the .htaccess file to hide the url parameters .
I would like to accept urls like
http://www.demo.com/74874 , that means http://www.demo.com?code=74874
You didn't mention what operating system you are using and instruction can vary, plus you didn't say if your are using HTTPD and if mod_rewrite is already installed/enabled. Assuming mod_rewrite is enabled and AllowOverride FileInfo is set in the server config, you could use this in your .htaccess:
RewriteEngine on
RewriteRule ^/([0-9]+) ?code=$1
This will accept any number as the path and rewrite it with the query string. If you want to keep any existing query string parameters, you would need to add [QSA] to the end of the RewriteRule.

Allow indexing subdirectories but not root directory

I have a site where subdirectories are generated automatically, and need to be indexable under .htaccess
However, I don't want someone to be able to go to the root of these subdirectories and to view them all. I also don't want anything other than these subdirectories to be indexable.
E.g.
/ ~ Has "Options -Indexes" (Non-Indexable)
/foo/ ~ Has "Options -Indexes" (Non-Indexable)
/foo/bar/ ~ Has "Options +Indexes" (Indexable)
/foo/baz/ ~ Has "Options +Indexes" (Indexable)
It's not possible for me to generate an individual .htaccess file for every subdirectory individually, the system I'm using doesn't support it.
I'm assuming there's no other way to solve this problem (without possibly using the Apache config), so I'm just allowing the index recursively (i.e. from /foo), then inside /foo 's .htaccess file:
Options +Indexes
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/foo[/]?$
RewriteRule (.*) / [R=301,L]
To just redirect people to the homepage. Also put a meta refresh redirect in there just incase.

htaccess - creating directories and files of the same name

I want to create a bunch of files without an extension showing at the end. The easiest way to do that was to do this:
/usa/index.php
/usa/alaska/index.php
/usa/alabama/index.php
/usa/california/index.php
What I want to do is this
/usa/alaska.php
/usa/alabama.php
/usa/california.php
and have it show up as:
/usa/alaska
/usa/alabama
/usa/california
However, I have one more level I want to add to this, the cities
/usa/alaska/adak.php
/usa/alaska/anchorage.php
/usa/california/los-angles.php
I don't want the ".php" showing up, but then each state exists as both a file and a directory. What I want is an htaccess rule that serves up the file version of the file, not the directory which is the default. I also want to strip the .php off of the end of the files so the final result looks like
/usa
/usa/alaska (alaska.php)
/usa/alaska/adak (adak.php)
I know I can get close to this by creating all the directories and using index.php for each directory, but then I will have thousands of directories each with one file in it and updating is a pain in the butt. I would much rather have one directory with 1000 files in it, than 1000 directories with 1 file in it.
Please, can someone point me in the right direction and know that I am doing this for all 50 states.
Jim
I would also suggest using a single php (e.g. index.php) file and redirecting all urls starting with usa to it, instead of separating them in different directories and files. The you'd need a couple of rewrite rules like the following
RewriteEngine On
RewriteRule ^usa/([^/.]+)$ index.php?state=$1 [L]
RewriteRule ^usa/([^/]+)/([^/.]+)$ index.php?state=$1&city=$2 [L]
So then in your index.php you'd only need to check the $_GET parameters.
Update:
If you don't feel comfortable enough to use a database and pull the needed data from there you could always use the parameters to dynamically include/require the needed files. Something like this
<?php
$source = ''; //or the 'ROOT' directory
if(isset($_GET['state'])) $source .= $_GET['state'].'/';
if(isset($_GET['city'])) $source .= $_GET['city'].'.php';
include($source); // here $source would be something like 'alaska/adak.php'
// and is assumed that the dir 'alaska' is on the same
// level as 'index.php'
?>
But to answer your original question nevertheless you could use the following .htaccess
RewriteEngine On
RewriteRule ^usa/([^/.]+)$ usa/$1.php [L]
RewriteRule ^usa/([^/]+)/([^/.]+)$ usa/$1/$2.php [L]
what about creating just one single file:
/usa/index.php
With
$_SERVER["REQUEST_URI"]
you can read the current URI.
Well, now if a user enters "http://domain.foo/usa/alaska" for example, he will get an 404 error of course.
But to call your index.php instead, you could write this line to the .htaccess:
ErrorDocument 404 /usa/index.php
Now the index.php receives everything what is written to the URI and you can match the result and include files or handle errors.
But maybe there is a better solution with .htaccess only, don't know. :)

.htaccess override IndexIgnore *, IndexIgnore nothing

I have a directory with an .htaccess file having the setting IndexIgnore *. How can I set a subdirectory to not ignore anything, or to ignore the negation of everything, so as to override the parent directory's IndexIgnore? Like IndexIgnore ^*, only a working version thereof?
Simply add IndexIgnoreReset ON before the new IndexIgnore directive.
And then, to show everything in the sub folder use IndexIgnore "."
Check the documentation at:
IndexIgnoreReset
I don't think it will be possible because IndexIgnore list is always appended in the existing list (from parent .htaccess). There is now way to overwrite this directive AFAIK.
In <Directory> block you can add:
IndexIgnoreReset ON
IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t
This will override config for this specific <Directory>

Resources