MODx htaccess problems and solutions



Yesterday I discovered that the flash banner wouldn’t load on www.asiandivingvacation.com, I suppose the crossdomain xml didn’t work like I expected it to.

Instead of messing around trying to make the crossdomain stuff work in Flash, I decided to just do a redirect like I have to do anyway and the problem would be solved. No one would be able to access the site through the www version anymore.

So I logged into cPanel and did the redirect, however when I loaded the page Apache complains that there is a never ending redirection loop in place and refuses to load it, great. I checked the redirection list in order to delete it and my new redirect is not there! So I opened a support ticket where I described the problem, this morning I got the answer from A2’s excellent support:

Hello,

It looks like there was an error in your .htaccess file, I have corrected the error and it now appears to be working as expected.

Thank you!
==============================================
Gerald Stuhrberg

And the page loads properly again. Gerald, I’m the one who should thank you for cleaning up my mess!

We still have to go to the bottom of this, here is the relevant lines in the .htaccess file that worked before I started redirecting in cPanel:

Options +FollowSymlinks
RewriteEngine On
RewriteBase /asd
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA,NC]

Note the /asd part, originally I tried with just / which worked on localhost, but not A2.

Here is Gerald’s new version:

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA,NC]
RewriteCond %{HTTP_HOST} ^www.asiandivingvacation.com$
RewriteRule ^/?(.*)$ "http\:\/\/asiandivingvacation\.com\/$1" [R=301,L]

Notice the two extra lines at the end combined with the original RewriteBase /. To be honest, Apache access files feels like a jungle, I can’t really explain 100% why this works so I’ll refrain. But at the moment it does with my MODx install, using pretty URLs and everything.

Update: I’m using MODx for a project at work at the moment on a staging server that are riddled with symlinks. Commenting out Options +FollowSymlinks takes care of things though. It looks like this at the moment:

RewriteEngine On
RewriteBase /online/project_x
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA,NC]

In this case online is in the www folder.

  • Digg
  • del.icio.us
  • blogmarks
  • Reddit
  • Simpy
  • StumbleUpon
  • Technorati
  • description
  • Ma.gnolia
  • Slashdot
  • Sphinn
  • Spurl

Related Posts


Tags: , , ,

Posts linking to this article:

jQuery Treeview with MODx and Wayfinder tutorial description
Hide Table of Contents for The Making of Asian Diving Vacation. jQuery Treeview with MODx Wayfinder; Flash Banner part 1 - jQuery Flash and document specific chunks in MODx; Flash Banner part 2 - The ActionScript and Shockwave ...

Subscribe with Google Reader

Viewing 2 Comments

    • ^
    • v
    Actually those two lines are included (slightly different) in the default htaccess file that is packaged with MODx but they are commented out so that you can choose the options that you want to use, with or without the www.

    I am not too sure what the differences are..

    Your edited one is:
    RewriteRule ^/?(.*)$ "http\:\/\/asiandivingvacation\.com\/$1" [R=301,L]

    While the one packaged with MODx is:
    RewriteRule (.*) http://www.example-domain-please-change.com/$1 [R=301,L]

    You can see that they are slightly different, not sure which one is "better".
    • ^
    • v
    Rewrite Rules
    1. RewriteRule (.*) http\://www.example\.com/$1 [R=301,L]
    2. RewriteRule ^/?(.*)$ http\://www.example\.com/$1 [R=301,L]
    (notice that I only put forward slashes for the special characters ' : ' and ' . ' in order to make them as regular string characters)

    Patterns
    1. (.*)
    2. ^/?(.*)$

    Parts of the Patterns
    1a. (.*)

    2a. ^
    2b. /?
    2c. (.*)
    2d. $

    #1 is more general than #2.

    Basically, #1 says that everything will be put into the $1 of the following substitution argument. However, #2 says that everything will be into the $1, except for a forward slash( / ) regardless of whether that forward slash actually exists. This is a pretty subtle, but important distinction to make. Say for instance that I had something like '/stringy'. #1 would substitute '/stringy' as 'http://example.com//stringy' while #2 as 'http://example.com/stringy'. But if I had something like 'stringy', both would turn out to be 'http://example.com/stringy'.

Trackbacks

close Reblog this comment
blog comments powered by Disqus