I've created web app and analyzed it with Google site analyzer.
In most cases I need to configure htaccess file. As I understand this file can be used only on Nginx or Apache server, but I don't want to use any of these.
I want to configure htaccess only with golang tools. Currently my app running on VPS server.
This project allows you to support the http auth standard with GO, zero apache code.
You can even use a password file created with the Apache htpasswd (bad) or htdigest (good) commands:
https://github.com/abbot/go-http-auth
You don't need .htaccess as it's only meant for Apache:
http://httpd.apache.org/docs/2.2/howto/htaccess.html
If you use Apache, external services like Google Site Analyzer can't see .htaccess since it's not served by Apache. It's kept private.
Everything Apache can do with .htaccess, Go can do with net/http or with a 3rd package like Gorilla to help.
If you want to do some constraints, then you may reference the following.
package main
import (
"github.com/gorilla/mux"
"io/fs"
"net/http"
"path/filepath"
)
type TxtFileSystem struct {
http.FileSystem
}
func (txtFS TxtFileSystem) Open(path string) (http.File, error) {
if filepath.Ext(path) != ".txt" {
return nil, &fs.PathError{Op: "open", Path: path, Err: fs.ErrNotExist}
}
return txtFS.FileSystem.Open(path)
}
func main() {
m := mux.NewRouter()
m.PathPrefix("/doc/").Handler(http.FileServer(TxtFileSystem{http.Dir("./doc")}))
}
That will only allow you to visit the file extension is .txt
Related
When pserve starts by default it runs the pyramid application in http://0.0.0.0:6543 however how can I changed it to http://0.0.0.0:6543/myapp
In the settings I can change the port but I haven't found elsewhere where to change the root path
In any WSGI application the environ['SCRIPT_NAME'] is very important here. It defines the root path for all urls in the app. The full path is environ['SCRIPT_NAME'] + environ['PATH_INFO']. Assuming you have done things properly in your app (for example request.route_url(..) will generate urls using this information) then you can simply remount your application elsewhere (the default SCRIPT_NAME is '') by instructing it that it should be something else.
There are a couple things you can do based on how you're deploying your application (if it's behind a proxy then things are slightly more complex). Let's assume you're just using a simple pyramid app hosted with waitress. You can move your app using the rutter[1] package which will match the /myapp/* path and send all requests to your app with the appropriate SCRIPT_NAME (myapp) and PATH_INFO.
The declarative config is the simplest for a pyramid app. Just install rutter and then update your INI file to mount your application at /myapp prefix:
[app:foo]
use = egg:myapp#main
[composite:main]
use = egg:rutter#urlmap
/myapp = foo
Note I renamed the app:main to app:foo because you can only have one wsgi component named main and we want it to be the composite.
[1] http://rutter.readthedocs.io/en/latest/#declarative-configuration-using-paste-deploy-ini-files
I am trying to set up an CodeIgniter project with NGINX. However, it is an already website which is online, say for example test.com. This means that the project also has $config['base_url'] = 'test.com'. But when I want to setup an NGINX server block I have to define the server name that is the same as the domain in base_url, according to this post. However, I want to have url test.dev for the development and test.com should just link to the online website. How do I achieve this?
Set your ENVIRONMENT variable. https://www.codeigniter.com/user_guide/general/environments.html
For your production
define('ENVIRONMENT','production');
and for development
define('ENVIRONMENT','production');
and in your config file you can check like this or any variables
if(ENVIRONMENT == 'development'){
$config['base_url'] = 'test.dev';
}else{
$config['base_url'] = 'test.com';
}
In CI, you can define a config.php file for each environment you are using.
In your config folder, create a development folder in which you place a config.php file with the base_url you need. Then, in that environment, CI will use that new file instead of the main config.php file.
Create Environments. Handling Multiple Environments
In your index.php Find a line which says
//define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
Under that line place a check on dirname and paste this code
switch(dirname(__FILE__))
{
case 'Path\of\your\live\server\folder':
define('ENVIRONMENT','production');
break;
case 'path\of\your\local\folder':
define('ENVIRONMENT','development');
break;
}
Now you have a global variable ENVIRONMENT which has values production or development. You can place a switch on this variable and give values to base_url in config.php or choose active group in database.php for DB credentials .
I need add a rewrite rule in my plugin, and distribute it with my code. All works fine if I put the rule in the .htaccess in the WordPress root folder, but I need distribute the plugin with my rule.
I try to put a .htaccess inside the plugin folder and try to use the add_rewrite_rule function but doesn't works either.
Here the .htaccess code that works correctly in WordPress root folder but doesn't works in my plugin folder:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule my-plugin/pages/tp(.*)\.php$ wp-content/plugins/my-plugin/pages/request.php?pid=$1
</IfModule>
I try the follow code in my plugin but doesn't works either:
add_filter( 'query_vars', 'add_query_vars' );
function add_query_vars( $query_vars )
{
$query_vars[] = 'pid';
return $query_vars;
}
add_action( 'init', 'add_init' );
function add_init()
{
$plugin_url = 'the-path-to-my-plugin-folder';
add_rewrite_rule('my-plugin/pages/tp(.*)\.php'
, $plugin_url . 'pages/request.php?pid=$matches[1]','top');
global $wp_rewrite;
$wp_rewrite->flush_rewrite_rules(); // I know this should be called only one time, but I put it here just to keep simple the sample code
}
But I always get the error that the URL wasn't found.
What I'm doing wrong? How can I do what I need? I searched for similar questions but none solve my problem.
My plugin folder structure is:
Main folder: /wp-content/plugins/my-plugin
------ /pages (sub folder)
-------------/request.php (script that should receive the request)
NOTE: WordPress Rewrite API is not the same as Apache Rewrite module.
WP Rewrite API doesn't redirect a request to another URL, it used to
parse current URL and fill query_vars array.
The issue is in the second parameter of you add_rewrite_rule function call. It has to start from index.php? and then there should be your arguments, like pid, for example:
"index.php?pid=$matches[1]...."
So your add_init function should be like this:
add_action( 'init', 'wpse8170_add_init' );
function wpse8170_add_init()
{
add_rewrite_rule('my-plugin/pages/tp(.*)\.php', 'index.php?pid=$matches[1]', 'top');
}
Don't forget to flush rewrite rules by visiting Settings ยป Permalinks page.
Further reading:
The Rewrite API: The Basics
The Rewrite API: Post Types & Taxonomies
WP handles the plugins from the /wp-admin directory with a PHP script (admin.php), like this:
http://MyWP.com/wp-admin/admin.php?page=MyPlugin/module.php
Therefore, .htaccess files in the plugin directory are not parsed when the plugin is called. They have to be placed in the wp-admin directory or in the root directory, as you already found out.
Although copying the .htacces file to the root directory when the plugin is installed -and deleting it when it is removed- is possible, I don't think it is the best option. Having .htaccess files in the WP space doesn't seem like a good idea.
Your second approach looks much better: Creating rewrite rules in the main script.
Looking at your code, I think the problem are the pattern (Incoming URL string to match) and possibly the substitution URL path ($plugin_url in your question).
The $rule parameter in the add_rewrite_rule() function should capture a segment of the URL (Above) used to call the plugin's modules.
I can't suggest anything else because you don't supply enough information about the plugin and it's directory tree, except what can be guessed from the regex in the rewrite rule. But, this is a general idea of a way to achieve what you need.
PHP 5.2.17
joomla 1.6.4
1and1 Linux shared server
php is running as cgi
Hi, I am trying to use a custom php.ini throughout my website. I know I can put a php.ini file in each folder, but that would not be feasible.
I searched online and found the following method:
1 - create your custom php.ini file and put it inside path/to/your/website/cgi-bin folder
2 - create the following php.cgi file
#!/bin/sh
exec /usr/local/bin/php5 -c path/to/your/website/cgi-bin
3 - upload php.cgi to /path/to/your/website/cgi-bin
4 - chmod +x php.cgi to make it executable
5 - include the following line inside .htaccess in my website root
Action application/x-httpd-php5 /path/to/your/website/cgi-bin/php.cgi
According to my understanding, after doing the above, php scripts on my website would start using my custom php.ini file instead of the default one.
Anyone can help? I spent a better part of the day trying to resolve this issue without success.
By the way, my account root (one level above my website root) has a .htaccess file with the following lines:
AddType x-mapp-php5 .php
AddHandler x-mapp-php5 .php
Thank you.
UPDATE 9/2/2011 - 19:37
tried including the following statement in .htaccess
SetEnv PHPRC /path/to/my/website/cgi-bin <- where my custom php.ini file is located.
According to this website it should have worked -> http://support.premiumreseller.com/index.php?_m=knowledgebase&_a=viewarticle&kbarticleid=85
But still nothing.
I will keep trying.
Any help appreciated!!!
UPDATE 2 - 9/3/2011 - 0:03 (WORKAROUND)
So, I couldn't find a solution for my problem. I decided to create a small php script to create hard links to php.ini in each directory that has a php script.
See below the code in case you are curious:
<?php
define('ROOT_DIR', $_SERVER['DOCUMENT_ROOT']);
define('FILE_PHPINI', ROOT_DIR . "/cgi-bin/php.ini");
processdir(ROOT_DIR);
function processdir($path)
{
$FlagNoPHP = true;
$localPHPINI = $path . "/php.ini";
foreach ( new DirectoryIterator($path) as $file)
{
if (!($file->isDot()))
{
if ($file->isDir())
{
processdir($path . "/" . $file);
}
else if ($FlagNoPHP && fnmatch("*.php*", $file))
{
$FlagNoPHP = false;
if (!file_exists($localPHPINI))
{
link(FILE_PHPINI, $localPHPINI);
}
}
}
}
if ($FlagNoPHP)
{
if (file_exists($localPHPINI))
{
unlink($localPHPINI);
}
}
}
?>
The above code looks inside each directory in my website and:
1 - if there is a php script and NO php.ini, creates a hard link to php.ini
2 - if there is NO php script and there is a php.ini, deletes the hard link (done in the last if of the function). I included this in order to clean up the filesystem of old php.ini files.
This worked for me.
I am still curious about an answer to my original problem.
I hope this helps someone!
Seems like you're taking the long way. Just modify .bashrc:
export PHPRC="/Volumes/Mac_Daddy/web_curr/public_html/php_osx.ini"
Result:
Configuration File (php.ini) Path: /usr/local/php5/lib
Loaded Configuration File: /Volumes/Mac_Daddy/web_curr/public_html/php_osx.ini
Scan for additional .ini files in: /usr/local/php5/php.d
Additional .ini files parsed: /usr/local/php5/php.d/10-extension_dir.ini
Or create an alias:
alias myphp="/usr/local/php5/bin/php -c /somewhere/someplace/php.ini"
or better yet man php.
I have a lighttpd server with website placed in /home/httpd/example.com/httpdocs and there I have a file called file.php. When I type http://en.example.com/file.php I would like to display file.php that is in default website directory (mentioned above).
So I used document-root described here:
http://redmine.lighttpd.net/wiki/1/Server.document-rootDetails
in this manner:
$HTTP["host"] =~ "en.example.com/file.php" {
server.document-root = "/home/httpd/example.com/httpdocs/"
}
But unfortunately when I type http://en.example.com/file.php into browser I get error 404. What I do wrong and how can I fix it to work?
In the case of the example URL http://en.example.com/file.php, the host is just en.example.com and not en.example.com/file.php (/file.php is the URL path). So try this:
$HTTP["host"] =~ "en.example.com" {
server.document-root = "/home/httpd/example.com/httpdocs/"
}