Fedora Core 5

301 Redirects with Apache .htacess file

I've just spent more time than I care to in the last couple of days trying to figure out rewriting urls with Apache, both through .htaccess files and directly in the conf file. Today was relatively painless, as I just had to come up with a way to 301 redirect all “extra domains” and some specific pages. For good measure, I also wanted to redirect non “www” domains to the canonical domain and also allow for future, yet unknown domains to be redirected. Here is what I came up with for an .htaccess file:



RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.yourdomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301]
redirect 301 /log.php http://www.yourdomain.com/fog.php

Pretty simple – the RewriteCond looks for any domain other than the one specified and upon matching, invokes the RewriteRule. The RewriteRuule simply uses a 301 redirect to the domain. The last line just redirects to a specific page. Looking at the output of Live HTTP Headers for firefox I noticed that it issues two 301 redirects if someone where to type http://www.extradomain.com/log.php. One redirect to get the proper domain, http://www.yourdomain.com/log.php, and then a second redirect for the actual page. Not a big deal, but I thought it would handle it all in one redirect since I wasn't using the L flag. I know, I have a lot to learn when it comes to mod_rewrite...

On a side note, why is it soooo diffucult to get 301 redirects in place from other people. Domain registers seem to only use 302 redirects and whenever I request a 301 redirect for a domain from another company, I either get silly responses like, “You can use the PHP header function to do a 301 redirect” (these are sites with a lots of individual html and php files, not a app running with a front controller) or it ends up being a 302 redirect.


While I am complaining, I might as well mention the bad behavior I experienced while cooking up some redirects. On my Fedora Core 5 desktop, I edited my /etc/hosts to include the domains and then set up a virtual host with aliases for the domains on my Apache server – this allowed me to use my browser and test the redirects locally with Live HTTP Headers. It seemed that the redirects would occasionally get cached somehow? Not sure whether it was my browser or on the server, but I was changing the .htaccess file and the changes would not take effect. If I cleared my browser cache/cookies AND restarted Apache, things seemed to clear up. But I thought Apache read .htaccess file on every request, and thus, changes should instantly take effect? If it was Firefox, then why didn't clearing the cache/personal data have any reliable effect? Maybe it was my desktop? Who knows...

Posted In: Linux, Fedora Core 5, Apache | 2 comments

Installing MySQL Query Browser on Fedora Core 5

I was visiting my parents back in Vermont last week, but right before I left I decided I wanted to install MySQL's Query browser. Running mysql from the command line works, but sometimes it is nice to have a GIU, especially since the program has help docs for syntax, multiple tabs open with queries and expandable table views (I always forget the names of rows in my tables while writing queries).



Fortuitously, I decided to search around before installing the program, and I quickly realized it wasn't as easy as issuing a yum command. I located a binary suitable for Fedora Core 5, and issued “ yum list installed | grep gtkhtml” and “yum list installed | grep gtkmm” to see if I had the prerequisite programs (gtkhtml3 and gtkmm24), as listed on the website with the binaries. I didn't have either of those, so I ran “sudo yum install gtkhtml3” and “sudo yum install gtkmm24”. Once those were installed, I downloaded the binary and MySQL Query Browser is working fine. Looking at the output from the previous yum list installed command, I have gtkhtml2, gtkhtml3 & gtkhtml36 - I can't remember now whether I also installed gtkhtml2 and gtkhtml36 for good measure, or if they were already there...

Posted In: Linux, Fedora Core 5, mysql | No Comments

Setting up Fedora Core 5 for Zend Framework

I installed Apache and MySQL through yum without a hitch and decided I needed to compile my own version of PHP 5. I ran into some problems compiling PHP5, but after resolving those, I had a working LAMP platform. The way ZF is currently set up, it really only works from the root directory of a site (you can use modified controller to get around this), although they are going to change the controller structure so it works in sub-directories in future releases. I have two different sites I want to build using ZF, so I decided to edit my /etc/hosts file to tell my computer to look at itself for two domains:

www.bolton.com localhost
www.tripvera.com localhost



Fedora checks /etc/hosts first when a domain is requested, so a matching line here will prevent it from querying a DNS server and allows you set up any domain you want, even if you don’t own it. You can also use the GUI in System->Administration->Network to add the same entry.
Now I had to modify httpd.conf (use “locate httpd.conf” if you are unsure where yours is) and I uncommented the virtual hosting line in the file, added the virtual directory and placed the mod_rewrite rules into the virtual host, rather than using an .htaccess file in the directory:


ServerAdmin your@email.com
DocumentRoot /var/www/html/bolton
ServerName www.bolton.com
ErrorLog logs/bolton.com-error_log
CustomLog logs/bolton.com-access_log common

RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php
AllowOverride All



Make sure to restart Apache to have the changes to httpd.conf take effect. Finally, I created a new file called .vimrc in my home directory and added “:set tabstop=4”. This is a config file vi opens whenever it is loaded and that command sets the tabs to 4 spaces, which is the recommended amount by ZF. Vi defaults 8 spaces, which I think it way too much and I use vi a lot for coding. I have been playing around with Eclipse, but that is a topic for another posting…

Posted In: PHP, Linux, Fedora Core 5 | 2 comments

Installing Flash on Fedora Core 5

Just started using Fedora Core 5. I installed it a couple of weeks ago, but have been working a lot and haven't played around much with it. I decided I needed to install flash and downloaded it from Adobe. I untared the file and followed their instructions, but it didn't work. I also tried issuing a "yum install flash-plugin", but that failed to actually download and install anything.



After searching the internet, I found the answer. I had to add a new repository and then yum would work. Went into /etc/yum.repos.d, created a new file and entered the following text and then yum worked like a charm:

[macromedia]
name=Macromedia for i386 Linux
baseurl=http://macromedia.rediris.es/rpm/
enabled=1
gpgcheck=1
gpgkey=http://macromedia.mplug.org/FEDORA-GPG-KEY


Posted In: Linux, Fedora Core 5 | 2 comments

Fedora Core 5

I finally got off my ass and installed Fedora Core 5 on my desktop. I had an early attempted foray into desktop Linux about 2 years ago, with a dual partition of Fedora Core 2 and Windows 2000. It worked alright, although I used Windows more than Linux and I ran into a couple problems installing different pieces of software on Linux. Then my hard drive failed, and I never bothered to really get my desktop up and running again, instead relying on my windows XP laptop.

This time around, I am somewhat more comfortable with Linux, although I still have a long ways before I am a power user. I am not bothering to install Windows and am going to try and use Linux almost exclusively. Notice the word “try”: I always seems to run into small problems with Linux, due to my unfamiliarity with it. But this time around, I think I can work through them. Besides, I need to learn Linux better and most of the programs I use now are open-source (Eclipse, Open Office, Firebox).

Posted In: Linux, Fedora Core 5 | No Comments