SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Jan 2012
    Posts
    253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool 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).

    Code:
    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.

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,891
    Mentioned
    138 Post(s)
    Tagged
    2 Thread(s)
    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

    Code:
    ## 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
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Addict
    Join Date
    Jan 2012
    Posts
    253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    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
    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.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •