Apparently, some servers require FollowSymLinks to be turned on. If mod_rewrite is refusing to work and just denying all access (particularly important when trying to implement MVC with a bootstrap file) try including this in the .htaccess file:Options +FollowSymLinks
Showing posts with label Apache. Show all posts
Showing posts with label Apache. Show all posts
Friday, 2 May 2008
Apache mod_rewrite refusing to work
More cool stuff with http.conf
Ok, I'm getting there. I know know a bit more about Apache's VirtualHost directive:DocumentRoot /var/www/phpweb20/htdocs
This gives an absolute path to the directory where your web files will be served from. It can be anything you want.<Directory /var/www/phpweb20/htdocs>
AllowOverride All
Options All
</Directory>
This says, for a given directory (and it says which in particular with the path) AllowOverride which allows me to use .htacess files in that folder. Not too sure what Options does yet.
The other cool bit is this line:php_value include_path .:/var/www/phpweb20/include:/usr/local/lib/pear
This tells the PHP module in Apache where to look for include files. Pretty handy.
Saturday, 22 March 2008
VirtualHosts in Apache, Leopard
There's a few key files when playing with Apache WebServer. They are all
Virtual hosts are a good thing to set up if you're working with a lot of websites. People talking about enabling the following line beginning with
This is fine, but it doesn't really do anything, it just gets Apache to pull in that extra configuration file when starting up. In fact, you can keep that file commented out (not used) and put virtual directory right there, in the
I'm sure loads can be changed, and I'm not sure what all of it does yet, but get this in and edit the rest.
Once this is done, you need to setup your hosts file. This can be found in
The IP address is equivalent to "
.conf files, the most important being http.conf. In Leopard this is at etc/apache2/. Editing this file is pretty straight forward, it's very templatey - find out where it's done once, then copy, paste and edit.Virtual hosts are a good thing to set up if you're working with a lot of websites. People talking about enabling the following line beginning with
Include in the http.conf file:
# Virtual hosts
#Include /private/etc/apache2/extra/httpd-vhosts.conf
This is fine, but it doesn't really do anything, it just gets Apache to pull in that extra configuration file when starting up. In fact, you can keep that file commented out (not used) and put virtual directory right there, in the
http.conf file. Here's the basic code for setting up a virtual host
<VirtualHost *:80>
#ZDS Name: redmonkey
ServerName redmonkey
DocumentRoot "/Users/michele/Sites/redmonkey"
ServerAlias redmonkey
ErrorLog error.log
Options Indexes MultiViews Includes
</VirtualHost>
I'm sure loads can be changed, and I'm not sure what all of it does yet, but get this in and edit the rest.
Once this is done, you need to setup your hosts file. This can be found in
/etc/ and it's simply called hosts (note: no file extension). Here add the following:
127.0.0.1 redmonkey
The IP address is equivalent to "
localhost" and then a name of your new hosts. From then on you should be good to go with your new hosting directory in Apache on Leopard.
Tuesday, 18 March 2008
.inc files and libraries
Use
require_once() to include files to use as a library. These files get interpreted by the interpreter but aren't called directly. They are conventionally given a .inc file extension, and they allow you to call functions and stuff hidden inside them. Quite useful.
Monday, 17 March 2008
mod_rewrite
First thing to get your head around is the fact that it's kinda backwards. Messy URLs still exist, you're just translating them from nice to messy for your code to understand.
After that, it's quite simple really. Regex expressions: from, to. Use
the
The only other thing I've discovered so far is there seems to be a default index being made by Apache which I haven't been able to disable yet. This default indexing causes Apache to ignore my rules and display any file in a directory by default if they share the same name i.e. if I have rules like
and within the directory there's also a file called
All of this can be written in a
After that, it's quite simple really. Regex expressions: from, to. Use
^ and $ to mark the beginning and the end of the expression to match. Here is a good mod_rewrite cheat sheet although there's loads of help online. Try to set a RewriteBase to set the base directory within the sitethe
[R] flag will redirect the user and the URL in the browser window will change automatically. The [L] flag will redirect behind the scenes but the users won't know. Use this for query-string stuff. Remember to turn the engine on (as it's off by default) with RewriteEngine on.The only other thing I've discovered so far is there seems to be a default index being made by Apache which I haven't been able to disable yet. This default indexing causes Apache to ignore my rules and display any file in a directory by default if they share the same name i.e. if I have rules like
RewriteRule ^$ catalog/ [R]
RewriteRule ^catalog/$ hello.php [L]
and within the directory there's also a file called
catalog.php, Apache seems to be ignoring the redirect to hello.php and just displays catalog.php as the index. I know this because if I change the filename and the redirect directory to something else I have the same affect. I'm still working on this, no idea how to do it.All of this can be written in a
.htaccess file.
Apache settings
Main files: httpd.conf and .htaccess. The first sets some site-wide settings. It seems to be similar to web.config in .NET. .htaccess works on a per-directory basis.
Subscribe to:
Posts (Atom)