AndyPerlitch
AndyPerlitch

Reputation: 4729

.htaccess RewriteRule Issue with Mac OSX server, not present on Unix server

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:

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

Upvotes: 0

Views: 1334

Answers (2)

AndyPerlitch
AndyPerlitch

Reputation: 4729

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

Upvotes: 4

Olivier Pons
Olivier Pons

Reputation: 15778

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 ;)

Upvotes: 0

Related Questions