egypturnash: (Default)
[personal profile] egypturnash
I got someone complaining that the menus on my site didn't load one too many times. They're generated by a little bit of Javascript, which tends to die on IE because people just turn off any and all scripting 'cause it's so full of security holes.

So I've converted it all to use a bit of PHP that generates the menu on the server end. This causes the problem that all my URLs will change, because I have to have everything be filename.php for this to work... or does it?

Not after a little fooling around with mod_rewrite, it doesn't! I shoved this in my .htaccess, above the code that prettifies the URLs to my gallery:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} ^(.*)\.html$
RewriteCond %1.php -f
RewriteRule ^(.*)\.html$ $1.php [ne,nc,l]


Translated into English, this tells the web server to do this:

If the user asks for a file whose name ends in .html, and if there's a .php file with the same name, give them the .php file instead. And stop doing the rewriting thing.

Yeah, I know, I could just stick the damn menu code in every file, but that means changing and re-uploading every file on my website when I change what's in the menu. It's a lot easier this way. Really. At least it is when you're a geek like me whose teeth grind at the thought of doing something by hand several times!

Date: 2006-08-04 01:35 am (UTC)
From: [identity profile] kajarainbow.livejournal.com
Easier? Maybe, maybe not. More fun? Definitely!

Date: 2006-08-04 02:15 am (UTC)
From: [identity profile] eriscontrol.livejournal.com
If you were a mage, your element would be mod_rewrite. That looks potentially useful.

Date: 2006-08-04 08:44 am (UTC)
From: [identity profile] mutleyjames.livejournal.com
I love these *ahem* geek updates of yours.

If I were a chimp and this update was a locked box, I would be all curiosity yet unable to open it wiothout throwing it against a rock.
*eeek*

Date: 2006-08-05 06:10 am (UTC)
ext_646: (Default)
From: [identity profile] shatterstripes.livejournal.com
I'm not sure why I post things like this. Maybe in case someone out there is looking to do this, asks Google, and gets lucky.

Date: 2006-08-05 06:15 am (UTC)
From: [identity profile] mutleyjames.livejournal.com
Don't get me wrong, I love them. It's me sitting there going - "can I make myself understand by squinting and looking thoughtful!!", it's funny!
:^)

Date: 2006-08-04 09:09 am (UTC)
From: [identity profile] mattlazycat.livejournal.com
That's pretty cool :)
I got even lazier last week when I redesigned lazycat.org, again with mod_rewrite magic. The idea was to never have to change content files to update includes or other non-content things:

RewriteEngine On
RewriteRule ^$ index.html [QSA]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule (.*) - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) view.php [QSA,L]


So basically all URLs instead get sent to view.php (which reads the URL, maps it to some layout-less html/php fragment in another directory - or to a 404 page - and displays it in the layout), and you can override by making an actual file. Cheap-ass pseudo-CMS. :)
Actually I'm pretty sure the last two RewriteConds are superfluous, but I don't dare touch it now that it works!

Date: 2006-08-04 03:08 pm (UTC)
ext_646: (Default)
From: [identity profile] shatterstripes.livejournal.com
As I was changing the six or seven solid HTML files that make up my site to my new menu calls, I thought "I should just shove this into a CMS". But that would be more work than it's worth. Especially since I'd probably end up having to update all my stuff in the future through a web form instead of FTP, ugh.

Date: 2006-08-04 03:25 pm (UTC)
From: [identity profile] mattlazycat.livejournal.com
Mmn, yeah, I cringed at the same thought, so I do exactly as you say - edit html/php fragments in whatever editor is to hand (okay, TextMate), then FTP it into a folder called content. Have a look at my not-CMS-CMS (http://lazycat.org/tmp/view.phps) if you want, it's about 48 lines of php including comments. (Not called lazycat for nothing!)

Date: 2006-08-04 09:47 pm (UTC)
ext_646: (Default)
From: [identity profile] shatterstripes.livejournal.com
Yay for Textmate. It's the first text editor I ever decided to shell out cash for!

I dunno if I could get by with something quite that simple and ubiquitous; I have some basic design rules but each page of my site has a lot of unique layout going on. Going to a minimal CMSoid thing might be slated for the next redesign, which is probably coming in, oh, 2011 or so, if I keep this one as long as I kept my old site. (Which generates the headers with a little cgi-bin I wrote in C.)

Profile

egypturnash: (Default)
Margaret Trauth

October 2020

S M T W T F S
    123
45678 910
11121314151617
18192021222324
25262728293031

Most Popular Tags

Expand Cut Tags

No cut tags
Page generated Jun. 30th, 2025 10:43 pm