Week Six.
Getting the Files to work on your Computer.
1. We were playing with Mod_Rewrite in Apache, this directive is
controlled in 1 or 2 ways, 1. via the httpd.conf file (which is the
main apache rule set / configuration which is located in /MAMP/conf/
apache/httpd.conf, or 2.) via the .htaccess file at the top of the web
main directory (in our case blog).
2. In your httpd.conf file we added another <Directory directive.
<Directory "/Applications/MAMP/htdocs/blog">
Options +FollowSymLinks
Options +Indexes
RewriteEngine ON
# how does this work?
# Alias soft_link hard_link
#Mod_Rewrite (blog_entry.php?action=view&page=<?= title ?> (formatted)
RewriteRule ^hackerblog/(.*)/(.*)$ blog_entry.php?action=$1&id=$2
RewriteRule ^hackerblog/(.*)$ blog_entry.php?action=$1
</Directory>
Add this chunk of code to your httpd.conf file on or around line 500.
This allows us to dynamically rewrite the url of the blog page.
Ex:
1.
http://yourdomain.com/blog/blog_entry.php?action=show&id=blog-page-2
(acceptable)
2.
http://yourdomain.com/blog/hackerblog/show/blog-page-2 (much more
acceptable)
This works because:
^hackerblog/(.*)/(.*)$ blog_entry.php?action=$1&id=$2
This says.
^(start of the line) + hackerblog + / + (action variable which equals
"show") + / + (id variable which equals "blog-page-2") + $ (which
means end of the line)
so you start the line with hackerblog followed by "show" / and finish
with "blog-page-2" and then end the line. (/hackerblog/show/blog-
page-2)
---------------------------------
If you look in the code. $_REQUEST['action'] is the PHP method for
bringing the value from action out of the url.
eg. $var = $_REQUEST['action']; echo $var; //show
---------------------------------
Pitfalls
------------
1. You must create a Database to work with (we created "hacker_blog")
2. You must import the sql file (hacker_blog_2010-05-18.sql) (the
process.txt file shows you some of the code broken out in SQL format -
to learn from)
3. Double Check that LoadModule rewrite_module modules/mod_rewrite.so
is not commented out in your httpd.conf file, this is done by default
in Window's Machines.
4. Check the clsGlobals.php file (/classes/clsGlobals.php), this has
your username, password, and port for MySQL. You need to update this
to reflect your environment, otherwise this will fail, you need a DB
to communicate to.
Good Luck, and please everyone download the files from Week 6, and get
them running so you can continue to learn the MVC Pattern, Pseudo
Factory Pattern, and how to think about Best Practices for building
larger web systems and keeping them under control.