|Rewrite or RewriteMap for this url handling|
| 3:49 am on Apr 23, 2012 (gmt 0)|
I'm not sure of the best way to go about handling the following url rewriting...
while having the following pages...
I want to hide the .php extension off all pages, and prefer to have the user's profile page as shown above instead of http://www.example.com/profile/user.
Any insight would be greatly appreciated.
| 4:18 am on Apr 23, 2012 (gmt 0)|
|prefer to have the user's profile page as shown above instead of http://www.example.com/profile/user |
The only risk you run is structuring the site wrong and having someone register as help, about etc. and hijacking your page with a user profile page.
Just make sure you process all of your page names ahead of profile pages.
Personally, I'd kick the whole thing into a PHP script and do your redirecting and dispatching from inside the script. Building and updating a rewitemap to redundantly look up customer profiles is a bit of a waste. From the PHP script, once you've confirmed the name exists in the database you can dispatch the profile page just as easily without maintaining an extraneous map, or program, and all the hassle that goes along with it.
| 4:41 am on Apr 23, 2012 (gmt 0)|
So in .htaccess, redirect everything within the top level directory to one file. And then have that one file pull in other files using includes? Is there not a way to dynamically do that using mod_rewrite or rewritemap?
On a previous site of mine, I was able to set user profile pages at the root easily since all the other files (index.php, about.php, contact.php) were still being displayed with their extensions. So basically, if the page did not contain a period I knew it was a user profile page. But now, as I mentioned, I'm wanting to drop the .php extension off all pages.
| 4:54 am on Apr 23, 2012 (gmt 0)|
If you have a ton of user profiles doing it via PHP is best.
Rewritemaps don't work in .htaccess, you have to be able to modify the apache conf file itself, or in a hosting account the httpd.include or vhost.conf of whatever it's called on your control panel. Access to those files is what usually stops most on shared hosting from using rewritemaps.
Obviously you can do it with .htaccess and rewrites, but if you're talking more than a few entries, like 1K members or some such, you won't want Apache processing a long linear list for each file access as performance will go out the window.
Guess the best method really depends on how much volume you expect and whether you have access to more than just Apache's .htaccess, which you didn't convey. If you expect a lot of members, you must plan ahead and do it right as this will just be a waste of time when you have to redo it right later when performance becomes an issue. Obviously rewritemaps can be pretty quick if you use DBM or an application that has access to your MySQL database for the member profile pages.