NoPic eZine
  
Home
Impressum/Imprint
Datenschutz/Policies
 
1.Issue 2006.06/1
 1.1.phpWebSite 1.0.0RC1 released
 1.2.Installing pWS 1.0.0rc1
 1.3.Running thru install
 1.4.First anonymous touch
 1.5.Exploring fallout surface inside
 1.6.Module substitution
 1.7.Directory Tree
 1.8.Database Tables
 1.9.ReadMe summary
   Access.txt
   bbcode.txt
   Cache_Lite.txt
   Categories.txt
   Clipboard.txt
   ControlPanel.txt
   Converting_Modules.txt
   Cookie.txt
   CREDITS.txt
   Database_Class.txt
   DB_Pager.txt
   Demographics.txt
   devdoc.modlayout.txt
   Developer_Rules.txt
   Editor.txt
   Forms.txt
   INSTALL.doc.txt
   Key.txt
   Known_Errors.txt
   Language.txt
   LICENSE.txt
   MiniAdmin.txt
   Mod_Rewrite.txt
   Module_Development.txt
   My_Page.txt
   README.doc.txt
   README.txt
   Related.txt
   Search.txt
   Settings_Class.txt
   SmartTags.txt
   Style_Format.txt
   template.txt
   Theme_Creation.txt
   Using_Javascript.txt
   Version.txt
   WYSIWYG.txt
 1.10.Using module WebPages
 1.11.Using module MenuManager
 1.12.Using webPages Editor
 1.13.Styling and Themes

    en

Mod_Rewrite.txt

Using Mod_Rewrite with phpWebSite
by Matthew McNaney
---------------------------------------------------------------------

When writing a module, you may find that some of your links are
getting rather complicated.

For example, say you are writing a module that looks at news
articles. You have link to an article on your home page and it looks
something like the following:

http://www.mysite.com/index.php?module=article&action=view&id=5312

Using mod_rewrite functionality, you could change that link to:

http://www.mysite.com/article5312.html

This is more straight forward, easier for search engines to index, and
much easier to explain over the phone. PhpWebSite can help you achieve
this.

Before you start trying to write modules that take advantage of this,
you will need to make sure your installation of phpWebSite supports
it.

First off, you have to be running Apache. If you are not, it won't
work. There may be solutions for Microsoft IIS and other web servers
but you will have to learn the differences yourself.

Second, you need to configure Apache to use mod_rewrite. Look in your
httpd.conf file for this line:
LoadModule rewrite_module modules/mod_rewrite.so
Add it if it is not there and restart your server.

Third, look in your phpWebSite root directory and you should see a file
named ".htaccess" (note the period). Uncomment all the lines by
removing the pound sign (#) in front of each line.

Finally, you will need to configure phpWebSite to use mod_rewrite. Go
into your config/core/config.php file and change the define to:
define("MOD_REWRITE_ENABLED", TRUE);

Your site should be ready to use mod_rewrite now.

Making your Module use mod_rewrite

The rewrite function is very basic. All it facilitates are simple user
accessible commands. You won't be accessing administrative
functionality using rewrite as it is unnecessary. Pages that can not
be viewed by the general public have no need to use rewrite.

You will need a way to 'catch' the request for viewing an item in your
module. Let's look at our previous example:

http://www.mysite.com/article5312.html

When this is sent to phpWebSite, it is going to go to the article
module and tell it that it wants to view article 5312. It will rewrite
the address to:

http://www.mysite.com/index.php?module=article&id=5312

You are sending two bits of information:
1) what module you are using,
2) what the id should be used.

Since I am only using the mod_rewrite to view items, my index file
assumes that if it only getting an id then this must be a user viewing
a file.

In my index.php file, I may have something like the following.

if (isset($_REQUEST['id']){
  $article = & new Article($_REQUEST['id']);
  $article->view();
}


Keep in mind however that not everyone will use mod_rewrite, so you
should plan accordingly.

if (MOD_REWRITE_ENABLED == TRUE)
   $link = 'article' . $id . '.html';
else
   $link = "index.php?module=article&id=5312";


One more quick note. When phpWebSite uses mod_rewrite, it has to make
sure that relative links in your theme still function. Therefore, the
layout module will insert the following in with your metatags:

<base href="http://www.your_site_address.org/" />

If it doesn't do this, the relative links (i.e.images, javascript,
style sheets) will start looking in directories below the fake address
sent to the page. The only problem with this is that if you output
anything outside of using the Layout module, it will disrupt this
header statement and your style sheets and images may have problems.

To prevent this, make sure that all output is through Layout and that
you catch errors using the Error class.

    en

Copyright © 2006, VbID Verlagsbüro GmbH
pWS modules dcP, dcT, dc4db, Copyright © 2006, VbID Verlagsbüro GmbH
This Site is powered by phpWebSite © The Web Technology Group, Appalachian State University