Interesting Mod_Rewrite Problem with GoDaddy

So, here’s an interesting problem that of course, just “happened” all on it’s own about three days ago. In short, mod rewrite has been working for almost a year, and without any changes, has stopped working for certain rules within the .htaccess file. After multiple phone support sessions with GoDaddy, they can’t find anything wrong. See if you can help me out.

I have hosting with Godaddy for my website sticktacular.com. More importantly though is that my site yourprofolio.com is hosted on this sticktacular.com within the folder YourProFolio/. (So, “http://yourprofolio.com/index.php” is the same thing as “http://sticktacular.com/YourProFolio/index.php”)

I use a .htaccess file within this YourProFolio/ folder which makes “pretty” little urls using mod rewrite. The “…/” in front of my paths is because of the sticktacular.com/YourProFolio hosting with the domain being yourprofolio.com in case that is confusing. Here’s an abbreviated version of my .htaccess file to show you examples of what’s working and not working:


RewriteEngine on

RewriteRule ^features$ ../features.php [NC] [L]
RewriteRule ^support$ ../support.php [NC] [L]
RewriteRule ^([0-9a-zA-Z_-]+)$ ../ProFolio/index.php?user=$1 [NC] [L]
RewriteRule ^([0-9a-zA-Z_-]*)$ ../index.php [NC] [L]

AddHandler x-httpd-php5 .php  
AddHandler x-httpd-php .php4  

Here’s how my site’s set up on the sticktacular.com hosting:


sticktacular.com
  /Root Directory
     -index.php
     /YourProFolio
        -.htaccess
        -index.php
        -features.php
        -support.php
        /ProFolio
           -index.php


Now, here’s the problem: when I go to yourprofolio.com, up comes the index.php file, which is good and that’s how it should be just like on basically any other site. But, when you click on a link, say, “Features” (which points to “http://yourprofolio.com/features”, which as you see in the .htaccess file, should show the page features.php, it doesn’t work! It comes up with an “Oops! This link appears to be broken” kind of page in my browser.

Now, where it gets even more curious, when you go to “http://yourprofolio.com/test” or “http://yourprofolio.com/zachkrasner” or any other link not specified in my .htaccess file, it should, and does, as according to my RewriteRule, brings up the the page “http://yourprofolio.com/ProFolio/index.php?user=test” (or index.php?user=zachkrasner or whatever link you’re going to). This works as it should. The reason why it’s interesting is because it seems to be working when the .htaccess points to a different directory other than the one in which it is located.

This is “all of a sudden” (I know, I know… I probably did something…even though I really don’t think I did) started happening across with all my .htaccess files in different directories in my sticktacular.com hosting about 3 days ago.

Does this seem familiar to anyone? Any ideas why this is happening? I have paying users using my site so any help at all is more appreciated than you can imagine! Thanks, and if anything is confusing, please ask! I will be online for the next couple hours and constantly checking back.

Don’t you just love it when websites decide to break down on their own? I also have that every now and again :-/

Anyway, let’s go through your .htaccess

The first thing to note is that if you want to apply multiple flags to one rule, you need to combine them like [NC,L], not [NC] [L].

[NC] stands for No Case, which is to say “make this rule case insensitive”. Since you have both a-z and A-Z in the character range in the third and fourth rule, they are already case insensitive on their own, and you can drop the [NC] flag on those rules.

Secondly, I would merge the first and second rule.

Lastly, what is the fourth rule supposed to do? It looks a bit weird.

So far, you’d get


RewriteRule ^(features|support)$ ../$1.php [NC,L]
RewriteRule ^([0-9a-zA-Z_-]+)$ ../ProFolio/index.php?user=$1 [L]
RewriteRule ^([0-9a-zA-Z_-]*)$ ../index.php [L]

AddHandler x-httpd-php5 .php  
AddHandler x-httpd-php .php4

Also, do you have .php4 files? If not, I’d drop the second AddHandler line since you don’t need it.

thanks for your input, but any idea on why it won’t put to within the same directory?

Fixed it!

Added to the very top of my file


Options FollowSymLinks
Options -Multiviews


Ah good old MultiViews again. Why they ever built that useless “feature” is beyond me. It does more harm than good :-/

Glad you fixed it, and thanks for posting the solution.

No problem. I actually think it might be the first part, but without both of them, it’s not working. Anyways, what does multiviews even do? I understand a little, but I couldn’t explain it…

An example of multiviews is that if you have it enabled and request /images/someimage.jpg where /images is not an existing directory, it will feed to request to images.php if that exists (or other extensions, if available, not sure about that).
And it does this before mod_rewrite kicks in. So if you have an images.php and want to use to create a fake directory for images served by PHP, and you want to use mod_rewrite, you’re SOL. Unless you disable MultiViews of course.

So if you have MultiViews enabled this won’t work:


RewriteEngine On
RewriteRule ^images/([a-zA-Z0-9.]+)$ images.php?imageId=$1 [L]

An example of multiviews is that if you have it enabled and request /images/someimage.jpg where /images is not an existing directory, it will feed to request to images.php if that exists (or other extensions, if available, not sure about that).

This sounds like the server could potentially be doing a lot of run-around make-work if an incorrect link is created somewhere that people click on. And then Apache does a bunch of mod_rewriting. Apache’s not slow at rewrite, but they do eat time, and more complex ones eat more time. Like, “keep throwing stuff at it until we get a valid file”. No wonder DK used the 'Splosion Smilies" for multiviews.

DK used the explosion smileys for (.*) which is a gazillion times more evil than multiviews.
He called it lazy regex, which is technically incorrect seeing as it is greedy regex. When I asked him about it he explained he meant “regex for the lazy”; too lazy to type what I really mean, so I’ll just eat anything and everything, regardless if I should allow it or not :slight_smile:

But yeah, MultiViews is a good one for Apache to start chasing it’s own tail. As is starting a substitution URL with a slash (when you’re not using mass virtual hosting; if you are you have to use the slash because otherwise it doesn’t work), and writing rules without the [L] flag.