Updating .htaccess files from Apache 2.0.59 to 2.2.21

I just bought a new Mac and upgraded MAMP. I’m now using the following versions:

Apache 2.2.21, PHP 5.3.6, MySQL 5.5.9

These are the versions I used previously:

Apache 2.0.59, PHP 4.4.7, MySQL 5.0.41

Can anyone tell me how I should update my .htaccess files?

Below is an example of my files. This particular example is a little unusual in that the website’s home page itself functions as a dynamic page. In other words, there are About and Topics sections (MySite/About, MySite/Topics) with dynamic pages (e.g. MySite/Topics/Roses), but dynamic pages can also be displayed off the home page (e.g. MySite/Planets, MySite/Stars).

I should also add that I prefer that trailing slashes NOT be displayed. It causes some confusion in my stats, where I get so many hits for Topics/Roses and so many hits for Topics/Roses/. I’d like to direct all the traffic to Topics/Roses.

If you see anything else I should change (or add) I’m all ears (or eyes). :wink:


RewriteEngine On
# Add /? before first $ in every row if you want optional trailing slashes.
RewriteEngine On
RewriteRule ^test\\.htm$ test.php [L]
Options -MultiViews

# php_value magic_quotes_gpc 0
php_flag magic_quotes_gpc Off

RewriteRule ^About/([a-zA-Z0-9()_/-]+)/?$ About/index.php?bout=$1 [L]
RewriteRule ^Topics/([a-zA-Z0-9()_/-]+)/?$ Topics/index.php?topic=$1 [L]
RewriteRule ^/?([-a-zA-Z0-9_/]+)/?$ /index.php?area=$1 [L]

Thanks.

There aren’t any major differences between minor versions of Apache AFAIK, and the .htaccess looks fine to me.

As for the trailing slashes, what you need to do is check if the URL ends in a slash, and if it does redirect to the URL without the slash. So instead of 1 rule for each directory, you get two rules.

Something like this


## About
# Redirect with trailing slash to no trailing slash
RewriteRule ^About/([a-zA-Z0-9()_/-]+)/$ About/$1 [L,R=301]
# Normal rewrite
RewriteRule ^About/([a-zA-Z0-9()_/-]+)$ About/index.php?bout=$1 [L]

## Topics
# Redirect with trailing slash to no trailing slash
RewriteRule ^Topics/([a-zA-Z0-9()_/-]+)/$ Topics/$1 [L,R=301]
# Normal rewrite
RewriteRule ^Topics/([a-zA-Z0-9()_/-]+)$ Topics/index.php?topic=$1 [L]

## /
# Redirect with trailing slash to no trailing slash
RewriteRule ^/?([-a-zA-Z0-9_/]+)/$ /$1 [L,R=301]
# Normal rewrite
RewriteRule ^/?([-a-zA-Z0-9_/]+)$ index.php?area=$1 [L]

I’ve removed the / in front of /index.php in the last rule because you don’t need it.

Please note that if you have files without extensions in either of those paths, those will not got served, but they will be sent to the php file as well! If you don’t have such files (which you most likely don’t) there is no problem, but if you do we should add a bit more magic :slight_smile:

Well, I’ll find out shortly. I think I discovered some sort of problem with my PHP or MySQL installation that I need to figure out.

Anyway, thanks so much for tips - especially that trailing slash fix. :wink: