apache

Url manipulation with mod_rewrite and php-catcher for beginners

Url manipulation is one of the hottest areas on the new generation web (2.0). It provides more security and flexibility. It is user and search-engine friendly. The most popular combination is Apache-webserver + mod_rewrite + server-side catcher(mostly a php-file). In this tutorial we use very short examples to make it easy for newbies.

Why url manipulation & mod_rewrite?

  1. more security: hide file location
  2. shorter urls without file extensions like .html
  3. easy to remember / recommend urls
  4. search engine friendly

[warn] [client 1.2.3.4] mod_fcgid: HTTP request length 137744 (so far) exceeds MaxRequestLen (131072), referer

As I want to add a forum entry I got Apache's 500 server internel error. i tried to change .htaccess, php-conf etec but no success.

Error was: [warn] [client 1.2.3.4] mod_fcgid: HTTP request length 137744 (so far) exceeds MaxRequestLen (131072), referer: http://example.com/node/add/forum/1

After a research check error-logs of virtual host I found that /etc/apache2/mods-available/fcgid.conf must be changed.

I added following directive:

MaxRequestLen 157286400

apache2ctl fullstatus /usr/sbin/apache2ctl: line 119: www-browser: command not found

When I execute following command to see apache's full-status I get just an error message:

apache2ctl fullstatus 
/usr/sbin/apache2ctl: line 119: www-browser: command not found

Any idea how to monitore Apache on debian Lenny?

Thanks a lot!

Multiple Virtual Hosts on Localhost of Apache / WAMP

You want to test multiple domains/sites on your local computer. Each site need to run on root level without urls without subdirectory. You have to create multiple vhosts. For each virtual host creata an entry in windows host file: hosts
Run a text editor as administrator to have right to make changes under windows.

C:\Windows\System32\drivers\etc\hosts :

127.0.0.1       www.mysite1.example
127.0.0.1       www.example.ku

httpd.conf :

NameVirtualHost 127.0.0.1

Function ereg() is deprecated in C:\wamp\www\drupal\includes\file.inc on line 902

I am trying to install Drupal 6.15 on WAMP with PHP version 5.30 and Apache 2.2.11 but I get following error:

Deprecated: Function ereg() is deprecated in C:\wamp\www\drupal\includes\file.inc on line 902

It is a 64bit Win7 and error_reporting is set to : E_ALL & ~E_NOTICE

I have already tried with : E_ALL & ~E_NOTICE | E_STRICT

It is just working with : E_ALL & ~E_DEPRECATED but I am not sure this is the right value.

Thanks for any help!

How to filter all html tags from each _GET and _POST request

If you have a small website which uses php and accept just plain text from users or visitors you need to filter each request to be sure that nobody sends html to hack your site. I put following two lines at the top of my php file. Of course you can add the third line for cookies.

	foreach($_GET as $k=>$v)	$_GET[$k] = strip_tags($v);
	foreach($_POST as $k=>$v)	$_POST[$k] = strip_tags($v);

Prevent hotlinking with htaccess and mod_rewrite

To stopping content stealing, just create an .htaccess file (or add to the existing file) and paste code below and upload/save it to your main directory(root of your homepage).

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example.com(/)?.*$     [NC]
RewriteRule \.(bmp|gif|jpg|jpeg|png|mp3|swf|avi)$ - [NC,F,L]

You can replace requested files with a ' don't hotlink' image file.

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example.com(/)?.*$     [NC]

.htaccess examples

redirect url with parameters

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} url_get_parameter_1=(.*)&url_get_parameter_2=(.*)
RewriteRule ^your/old/directory/file$ your/new/path/%1/%2 [R=301,L]

This code redirects :

example.com/your/old/directory/file?url_get_parameter_1=ALBUMS&url_get_parameter_2=HOLIDAY

to

example.com/your/new/path/ALBUMS/HOLIDAY

Force files to download (not be displayed in client/browser)

  

Apache Error: make_sock: could not bind to

I have installed Apache 2.2.4, PHP5 and Mysql5 for long time ago. Everything was perfect working but today when I try to start webserver it gives following error:

...
make_sock: could not bind to
 address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
Note the errors or messages above, and press the  key to exit.  27...

Any idea why it happens and how to fix it? Is there a way to update Apache without new installation. Because ok settings like httpd.conf etc.

Do I need suexec, suphp, php-suhosin, mod_security same time?

Just another question: Do I need PHP-Suhosin if I have mod_security already installed on my dedicated server? And what is the difference between Apache-Suexec and suphp or php-suexec, make sense to have both installed and in use? Because I have some strange problems with my website, sometimes my site is unreachable for me but if I disconnect and re-connect(change IP) the site is on. There is no server load issues or etc. I had been banned but I dont know who banned me, if mod_sec or apf or suhosin or any other tool.

Syndicate content

CafeWebmaster.com(CW) is a free online community for webdevelopers and beginners. Anybody can share their code, articles, tips, tutorials, code-examples or other webdesign related material on the site. Newbies can submit their questions and reply to existing questions. CW does not guarantee or warrant reliability of code, data and information published on the site. Use the site on your own risk. The site takes no responsibility of direct or indirect loss or any kind of harm to its users. The site also doesn't take responsibility of infected files or source code with any kind of infection or viruses, worms, spywares, malwares, trojan horses. CW reserves the right to edit, move, or delete any of content for any reason.