0

I'm working on an aircraft website and using a .htaccess file to rewrite the URLS so they are seo friendly. Here is the file:

AddType application/x-httpd-php /(.*)
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^general-aviation-models/(.*)/(.*) /models.php?mfg=$1&model=$2
RewriteRule ^general-aviation/(.*)/(.*) /general.php?page=$1&sub=$2
RewriteRule ^general-aviation/(.*)  /general.php?page=$1
RewriteRule ^general-aviation  /index.php
RewriteRule ^military/(.*) /military.php?page=$1
RewriteRule ^military-models/(.*)/(.*) /military-models.php?mfg=$1&model=$2
RewriteRule ^military-models/(.*) /military-models.php?mfg=$1
RewriteRule ^cart/ /cart.php
RewriteRule ^contact/ /contact.php
RewriteRule ^commercial/(.*)/(.*) /commercial.php?page=$1&sub=$2
RewriteRule ^commercial/(.*)  /commercial.php?page=$1
RewriteRule ^commercial/ /commercial.php
RewriteRule ^links/ /links.php
RewriteRule ^about/ /about.php
RewriteRule ^tour/(.*)  /tour.php?page=$1
RewriteRule ^tour/ /tour.php

ExpiresDefault "access plus 10 years"
AddOutputFilterByType DEFLATE text/plain

This has worked on a *nix-based server as well as on MAMP in my local development environment, however upon migrating to a Mac OSX server, several (but not all) of the rules fail. In particular, these fail:

RewriteRule ^military-models/(.*)/(.*) /military-models.php?mfg=$1&model=$2
RewriteRule ^military-models/(.*) /military-models.php?mfg=$1
RewriteRule ^commercial/(.*)/(.*) /commercial.php?page=$1&sub=$2
RewriteRule ^commercial/(.*)  /commercial.php?page=$1

Other notes:

  • the mod_rewrite module successfully loads (shows up in the Loaded Modules section of phpinfo())
  • I have AllowOverride All in my httpd.conf file (in appropriate tags)
  • my server API is Apache 2.0 Handler

I have looked around SO for a while but haven't found much. I tried the first solution in this SO question but the added line caused this error in my logs:

/my_specific/document_root/.htaccess: DocumentRoot not allowed here

Any suggestions?

UPDATE:

Turns out Apache's Multiviews feature was turned on which ended up working for most of my rewriterules anyway, but was overriding them and caused the 4 failures listed. All I had to do was add this to the top of my htaccess file:

Options -MultiViews
Community
  • 1
  • 1
AndyPerlitch
  • 4,539
  • 5
  • 28
  • 43

2 Answers2

4

Turns out Apache's Multiviews feature was turned on by default which ended up working for most of my rewriterules anyway, but was overriding them and caused the 4 failures listed. All I had to do was add this to the top of my htaccess file:

Options -MultiViews
AndyPerlitch
  • 4,539
  • 5
  • 28
  • 43
0

Here's how I would change your rewriterules:

AddType application/x-httpd-php /(.*)
Options +FollowSymLinks
RewriteEngine On

RewriteRule ^/?$ /index.php [NC,QSA,L]
RewriteRule ^(tour|cart|links|about|military(-models)?|general-aviation|commercial|contact)/?$ /$1.php [NC,QSA,L]

RewriteRule ^general-aviation-models/([^/]+)/(.*) /models.php?mfg=$1&model=$2 [NC,QSA,L]
RewriteRule ^general-aviation-models/(.+) /models.php?mfg=$1 [NC,QSA,L]

RewriteRule ^general-aviation/([^/]+)/(.*) /general.php?page=$1&sub=$2 [NC,QSA,L]
RewriteRule ^general-aviation/(.+)  /general.php?page=$1 [NC,QSA,L]

RewriteRule ^military-models/([^/]+)/(.*) /military-models.php?mfg=$1&model=$2 [NC,QSA,L]
RewriteRule ^military-models/(.+) /military-models.php?mfg=$1 [NC,QSA,L]

RewriteRule ^commercial/([^/]+)/([^/]+) /commercial.php?page=$1&sub=$2 [NC,QSA,L]
RewriteRule ^commercial/(.+)  /commercial.php?page=$1 [NC,QSA,L]

RewriteRule ^military/([^/]+) /military.php?page=$1 [NC,QSA,L]
RewriteRule ^tour/(.+)  /tour.php?page=$1 [NC,QSA,L]

ExpiresDefault "access plus 10 years"
AddOutputFilterByType DEFLATE text/plain

By the way I'm sorry to say that, but there's room for improvement in your design.

In general people redirect all to index.php then decode the URL in Php code.

Think about it ;)

AndyPerlitch
  • 4,539
  • 5
  • 28
  • 43
Olivier Pons
  • 15,363
  • 26
  • 117
  • 213
  • Thanks for the answer! Unfortunately, the OSX server is still having problems with the aforementioned sections. By "decode the URL in php code, do you mean parse it and direct the request using php? I can see how that would eliminate my problem. Could you direct me to an SO article or somewhere I can see an example for this? Thanks! – AndyPerlitch Jan 28 '12 at 23:54
  • I didn't meant to change `contact` to `index` because I followed your Rewrite rules. It's just my comment after that which could have made you think that :) – Olivier Pons Jan 29 '12 at 10:32
  • Gotcha. Thanks so much for your help. I found a lot of stuff on the Front Controller pattern that I think addresses this very well. – AndyPerlitch Jan 29 '12 at 21:43
  • 1
    It turns out that the Apache's multiview function was turned on, overriding the .htaccess rules. I just added the following line to the top of my htaccess file: Options -MultiViews – AndyPerlitch Jan 30 '12 at 20:11
  • Nice =) Sometimes the smallest things are the hardest to find! – Olivier Pons Jan 30 '12 at 22:28
  • @AndyPerlitch Options -MultiViews works for me, please make that your answer as it will be missed by many – Ashley Feb 23 '12 at 12:09
  • @Ashley You are right, I just wasn't sure if it was proper etiquette to accept an answer, then answer my own question and change the accepted answer to mine. – AndyPerlitch Feb 23 '12 at 17:20