The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Redirect a few URLs: mod_rewrite map? Redirect directive?

I have a small website with about 50 pages, each page has a menu that links to the other pages, classic stuff.

I want to have my menus point to generic, or "clean" URLs.
Things like:

And, behind the scenes, I would redirect this to

The idea is that I want to be able to easily switch certain pages between html and php without having to rewrite all my menus.

I was thinking of doing this with mod_rewrite and a simple static rewrite map.
But I read that in this rather simple case it is also possible to use a Redirect directive.

Which solution is better? I would like to avoid messing things up for the user and for the search engines...

Thanks for your insights...
28 Projects Later Send private email
Saturday, March 08, 2008
The easiest solution is to create a directory called photos and then put your file as index.php or index.html in there. That way, you don't have to use mod_rewrite.
Troels Knak-Nielsen Send private email
Saturday, March 08, 2008
Thanks, simple indeed- hadn't thought of that!

There is only one minor issue, though, which is that the browser's address bar will show

(with a slash at the end).

I guess I can live with that if I can't find a better solution...
28 Projects Later Send private email
Saturday, March 08, 2008
If you don't want the slash, use mod_rewrite. Something like this should do:

RewriteEngine on
RewriteRule /photos /photos.php

A Redirect directive won't do what you want. Try it and see.
Sunday, March 09, 2008
Or more generally:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}  -f
RewriteRule  ^.*$  -  [L]
RewriteRule ^(.*)$  $1.php [L]

Line 2+3 allow files to be referenced directly, without mod_rewrite messing them up. This is necessary for auxiliary files, such as images css &c
Troels Knak-Nielsen Send private email
Sunday, March 09, 2008
Thanks guys

clcr: is there any reason why a series of RewriteRule's is better than a txt RewriteMap ?
28 Projects Later Send private email
Monday, March 10, 2008
In the keeping it simple vain, there are a couple of other approaches you could use.

Firstly, you could just have all files as *.php (even if they're just HTML). This won't help you if you change technology in the future of course.

You could also use MultiViews (Options +MultiViews in apache config) which means a URL of will return photos.php or photos.html depending on what it finds in the webroot. There is a small performance penalty however (nothing noticeable unless you have a huge traffic site).

Just some thoughts.

Russ Hall Send private email
Wednesday, March 26, 2008

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz