homepage Welcome to WebmasterWorld Guest from 54.237.184.242
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Rewrite or RewriteMap for this url handling
jwarren93




msg:4444084
 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...

http://www.example.com/someuser

while having the following pages...

http://www.example.com/help
http://www.example.com/contact
http://www.example.com/about

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.

 

incrediBILL




msg:4444091
 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.

jwarren93




msg:4444094
 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.

incrediBILL




msg:4444095
 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved