Tags: php

Mod_Rewrite Problems and Solutions

03/30/09 | by Charlie [mail] | Categories: PHP

So over the break I updated the Yale Drama Coalition website to have a reservation system! However, so that the addresses look pretty on posters, I wanted to use mod-rewrite, an apache webhost mod, to change the urls.

Basically instead of our Romance show url being:
http://www.yaledramacoaltion.org/view_show.php?show_id=31
it can now be accessed at:
http://www.yaledramacoaltion.org/romance
and
http://www.yaledramacoaltion.org/reserve/romance

Notice how those are much prettier (and easier to remember). Unfortunately, to do this requires some work at the top level of a website. It seems I accidentally got the file into my blog directory, so sorry to anyone who tried to get to the site in the past day.

Anyways, if anyone else is looking for help getting mod_rewrite to work, I found two very helpful resources:
this cheat sheet for mod rewrite was great and condensed all the information onto a single page!

Second, I was using the [R] tag for awhile, which literally redirects to the underlying page instead of masking it. The reason for this was that /reserve/ makes the page think it's in the reserve directory, so all the links break. To fix this I found a post on mod_rewrite forums which gave some solutions. Unfortunately, I've always used relative links, meaning I used the 5th option of a base tag to fix it.

Now everything's fine and dandy. This technique is great for search engine friendliness, is somewhat logical, and works better on print and when giving out the link!

Real information on my life to come later.

Permalink

Ever wanted a look inside the life of a Yale student? Here's your chance, I write about everything from the stress of school to the rewards of college social life. Join me as I vent about my daily life, struggles and triumphs.

Search

XML Feeds

powered by b2evolution free blog software