mod_rewrite

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

Redirect webpages with HTML, PHP, .htaccess, Java+Script, CGI-Perl, ASP.NET and ColdFusion

Here are examples of code how to redirect an old page/url/domain to a new one with most popular client+server side programming/scripting languages. We use 301 http status code (permanent redirect). If you need temporary redirection use 302 status code instead of 301. It is better to prefer server-side redirection, because some clients are surfing with javascript and http-refresh disabled browsers. Do not forget to test your code first!

.htacces and Mod_Rewrite (Apache Webserver)

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