Category Archives: Apache

Rewrite rules in .htaccess

RewriteEngine On RewriteBase   /mydir RewriteRule ^mydir/(.*) http://my_other_server.com/other_dir/$1 [P] RewriteRule    ^mydir/$  http://my_other_server.com/cgi-bin/other_dir/index.cgi [P] RewriteRule    ^cgi-bin/other_dir/index.cgi(.*)  http://my_other_server.com/cgi-bin/other_dir/index.cgi$1 [P] # RewriteCond %{REQUEST_URI}  ^index.cgi* RewriteRule   ^index.cgi(.*)  http://my_other_server.com/cgi-bin/other_dir/index.cgi$1 [P] RewriteRule    ^mydir/index.cgi(.*)  http://my_other_server.com/cgi-bin/other_dir/index.cgi$1 [P] RewriteEngine On RewriteBase   /mydir RewriteRule ^mydir/(.*) http://my_other_server.com/other_dir/$1 [P] RewriteRule    ^mydir/$  http://my_other_server.com/cgi-bin/other_dir/index.cgi [P] RewriteRule    ^cgi-bin/other_dir/index.cgi(.*)  http://my_other_server.com/cgi-bin/other_dir/index.cgi$1 [P] # RewriteCond %{REQUEST_URI}… Read More »

Apache variables

Server Variables are variables set by Apache, and held inside the super global array ‘$_SERVER’. They hold very interesting snippits of data available for use, and become very useful when developing PHP projects. $_SERVER[‘REQUEST_URI’] It return the URL in to access the page which is executing the script. If you need to type http://www.example.com/product.php?id=5 to… Read More »

Using Include into Virtual Host

If you want you can include other configuration file into a Virtual Host, but you must not define any other <VirtualHost *:8080> Include /etc/apache2/conf.d/my_other_conf/*.conf </VirtualHost> If you don’t define the virtual host *:80, all the configuration from standard httpd.conf will be loaded in all other Virtual Host.

Enable Apache 2 modules in OpenSuSE 11

OpenSuSE 11 has a strange and funny way for loading the modules. If you try to load modules by modifying an .conf file, you will be surprised when you will realize that at the restart, your change will be lost. You have two options: 1. Load that modules only when you need it, in a custom… Read More »

Apache mod_rewrite and OpenSuSE 11

If you have OpenSuSE 11, you will have a big surprise when you try to use mod_rewrite. You will not find any mod_rewrite. The only think you must do is to activate mod_rewrite with the following command: # a2enmod rewrite # rcapache2 restart

Redirecting user on different pages depending cookies

When you need to redirect a visitors to different pages depening on a value from a cookie you can use this code: RewriteCond %{HTTP_HOST}  ^mydomain.com$ RewriteCond %{HTTP_COOKIE} !MyDomainCookie RewriteRule  ^/$           /first-page.htm  [R=301,L] RewriteCond %{HTTP_HOST}  ^mydomain.com$ RewriteCond %{HTTP_COOKIE} MyDomainCookie=Value1 RewriteRule ^/$ /second-page.htm [R=301,L] RewriteCond %{HTTP_HOST}  ^mydomain.com$ RewriteCond %{HTTP_COOKIE} MyDomainCookie=Value2 RewriteRule ^/$… Read More »

Redirect a visitor to different pages depending on his browser

If you need to redirect users depending on their web browser, you can use this: RewriteCond  %{HTTP_USER_AGENT}  ^Mozilla.* RewriteRule  ^/$                 /homepage.max.html  [R=301,L] RewriteCond  %{HTTP_USER_AGENT}  ^Lynx.* RewriteRule  ^/$                 /homepage.min.html  [R=301,L] RewriteRule  ^/$                … Read More »

Modify a file from browser

#! /usr/bin/perl use CGI qw/:standard/; print “Content-type: text/htmlnn”; print “Modify the file:$file<br/><br/>”; $action = param(‘action’); if($action eq “”){ $file_content=””; open (MYFILE, “<“, $file); @lines=<MYFILE>; foreach $l(@lines){ $file_content.=$l; } close (MYFILE); print<<frm; <form action=”modify.cgi” method=”POST”> <textarea name=”file” cols=”150″ rows=”30″> $file_content </textarea> <input type=”hidden” id=”action” name=”action” value=”modify”> <br /><br /> <input type=”submit” value=”Modify!”> </form> frm } if($action… Read More »

Compile Apache modules

Sometime, you don’t find the .so file that you need. In this case you must search for it’s source codes and try to comile it. To have this option, you must have httpd-devel / apache-devel installed on your Linux machine. apxs2 -c -I/usr/include/libxml2 -i mod_line_edit.c This will complile mod_line_edit.so Cheers,