6 Replies - 2705 Views - Last Post: 06 May 2014 - 04:16 PM

#1 guyfromri  Icon User is online

  • D.I.C Addict

Reputation: 46
  • View blog
  • Posts: 818
  • Joined: 16-September 09

Creating clean URL's and paths

Posted 24 April 2014 - 10:38 AM

Hi All,

I'm sure this is a question as old as time but I can't seem to find the right terminoligy to get a solid answer on my searches.

Let's say I have my site and I want users to be able to create profiles. It seems like all major sites nowadays allow you to create something like mysite.com/user1.

I've been thinking about this and I have a few thoughts on it but I'm aware there's probably a standard to set it up and I'm just not sure how.

My Options
1) Create a directory for every user with an index. When generating the index, use some includes to pull the code from the file that should build that page.

2) Create a unique PHP page and alter my htcaccess file to assume .php extension if it's not a directory. This doesn't seem too hard.

My problem with these solutions is the obvious clouding of my root directory and the ability to control the files out there.


I'm just curious if anyone knows of anything that I could learn here or if those are the only two viable ways of accomplishing something of this nature?

As always, thanks in advance!!

Is This A Good Question/Topic? 0
  • +

Replies To: Creating clean URL's and paths

#2 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3569
  • View blog
  • Posts: 10,403
  • Joined: 08-June 10

Re: Creating clean URL's and paths

Posted 24 April 2014 - 10:45 AM

essentially you do URL rewriting on the server (e.g. in Apache you’d use mod_rewrite) and use a Front Controller Pattern for your application.
Was This Post Helpful? 1
  • +
  • -

#3 guyfromri  Icon User is online

  • D.I.C Addict

Reputation: 46
  • View blog
  • Posts: 818
  • Joined: 16-September 09

Re: Creating clean URL's and paths

Posted 24 April 2014 - 10:59 AM

Thank you but I'm still a little confused. I get the mod_rewrite piece but I'm not sure about a front end controller pattern? Is this something where I could house a directory of files or point that type of setup to a different file? Or would I still have to maintain a separate file for each URL in root?

Is it possible to say "Point mysite.com/user1 > pull information and data from mysite.com/master_layout.php" or am I just a crazy person?

lol thanks for the help :)
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5380
  • View blog
  • Posts: 27,350
  • Joined: 10-May 07

Re: Creating clean URL's and paths

Posted 24 April 2014 - 11:02 AM

View Postguyfromri, on 24 April 2014 - 01:59 PM, said:

Is it possible to say "Point mysite.com/user1 > pull information and data from mysite.com/master_layout.php" or am I just a crazy person?

You don't pull information. That's the purpose of url rewrites in .htaccess. Present the data from the server, but make the url display how you desire.

http://www.dreaminco...-with-htaccess/
Was This Post Helpful? 1
  • +
  • -

#5 ArtificialSoldier  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 469
  • View blog
  • Posts: 1,710
  • Joined: 15-January 14

Re: Creating clean URL's and paths

Posted 24 April 2014 - 11:36 AM

In essence, it will see a URL like example.com/username1 and internally it will handle the URL as if it was example.com/user.php?user=username1.
Was This Post Helpful? 1
  • +
  • -

#6 guyfromri  Icon User is online

  • D.I.C Addict

Reputation: 46
  • View blog
  • Posts: 818
  • Joined: 16-September 09

Re: Creating clean URL's and paths

Posted 24 April 2014 - 11:58 AM

That makes perfect sense. Thanks so much! Very easy to setup and exactly what I wanted! Awesome info to have!
Was This Post Helpful? 0
  • +
  • -

#7 guyfromri  Icon User is online

  • D.I.C Addict

Reputation: 46
  • View blog
  • Posts: 818
  • Joined: 16-September 09

Re: Creating clean URL's and paths

Posted 06 May 2014 - 04:16 PM

Hey Guys - My hard drive died so I wasn't able to respond to this or work on my site for a while. Anyway, I've tried to implement the code as suggested but I keep redirected to my index page. Am I doing something wrong here? Thanks again for all the help!

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

RewriteRule ^(.*)/$ menu.php?id=$1 [L,QSA]
</IfModule>


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1