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

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 <ESC> 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.

Fix Cpanel/WHM's easyapache and up2date issue (certificate verify failed)

Today morning woke up and saw httpd not running. I tried to install/update Apache using Cpanel's Easyapache script over webinterface(post 2086/2087) but no chance. I tried the same with ssh as root using putty but I got same error output like this:

Checking that all packages are present and up to date.
!! No method to auto repair package system !!
!! Please visit http://www.cpanel.net/support/could_not_ensurepkgs.htm for help with this error. !!
!! Restoring original working apache !!
!! Executing '/scripts/initsslhttpd' !!
!! Restarting 'httpd' ... !!

How to set up wildcard subdomains?

I want to setup wildcard subdomains. Also anything.example.com must be redirected or located to example.com. Can I do it with .htaccess or httpd.conf or do I need to change dns settings too ?

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.