views:

41

answers:

2

Thanks to everyone who has helped me with my clean URL quest. I'm almost there but want to lick this last thing.

.htaccess

RewriteEngine on

#REMOVE THIS LINE ON SITE LAUNCH!
RewriteBase /~accountName/

#Hide .php extensions for cleaner URLS
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

#calendar-expanded REST-ful URLs
RewriteRule ^calendar-expanded(/.*)?$ calendar-expanded.php$1 [L]

Options All -Indexes

<IfModule mod_security.c>
    SecFilterEngine Off
    SecFilterScanPOST Off
</IfModule>

# propagate php.ini file to all sub-directories
suPHP_ConfigPath /home/accountName/public_html/php.ini

my working url

www.example.com/calendar-expanded/4/mother-mother-in-concert/

a broken url

www.example.com/calendar/12/another-band-live/

There is no mod re-write for calendar/ obviously. My question is, do I absolutely need a rule for every page to avoid internal server errors if someone accidentally browses to the wrong page? The broken url is an example of that. I'd really love for the browser to return a 404 error instead.

I'm looking for a cond/rule that will cover "all other" urls except calendar-expanded. Is this doable?

Thanks. (@Gumbo I'm looking hopefully in your direction!)

A: 

Could you create a rule that matches everything and just have it at the bottom? The rewrite engine gives precedence to rules based on the order in which they appear in the .htaccess file.

George Edison
The rules are tested in the order they appear in the file. And the first rule that matches is applied.
Gumbo
@Gumbo: Exactly. Why wouldn't my idea work then?
George Edison
@George Edison: I didn’t say that it wouldn’t. It’s just that your explanation sounds a little bit confusing.
Gumbo
There. I fixed my answer.
George Edison
Possibly @George. Could I come up with it on my own? No! I love the principle behind this but I'm having a hard time wrapping my head around *how* to do it.
jeerose
@jeerose: Sorry, what I'm saying is to put a rule at the very end that matches everything and simply throws a 500 error. Since this rule is at the end, it will only match invalid requests since the valid ones will have been matched earlier.
George Edison
+2  A: 

I could reconstruct this behavior and trace it back to this condition:

RewriteCond %{REQUEST_FILENAME}\.php -f

Here REQUEST_FILENAME does only contain the filesystem path to calendar within the same directory. And that appended with .php is an existing file so the condition is true. But $1 does contain the full requested URL path that is now appended .php. This keeps repeating until the internal counter exceeds its limit.

A solution to that is to use %{REQUEST_FILENAME}.php in the substitution as well:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_FILENAME}.php
Gumbo
I wish I had more to offer than a checkmark and upvote. Where do I send the beer (or coffee)?! Thank-you so much for that and all your time. Seriously if you have a developer "buy me a coffee" link, I'll use it.
jeerose
@Gumbo, got my vote for moderator.
jeerose