Apache Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsSystem AdministrationApache Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 18th, 2012, 04:02 PM
HDFilmMaker2112 HDFilmMaker2112 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 181 HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 11 h 9 m 44 sec
Reputation Power: 27
Rewrite to different kinds of php conditions

How would I got about using mod_rewrite to rewrite:

www.domain.com/index.php?home to www.domain.com/home

but also have
www.domain.com/index.php?profile=John to www.domain.com/John

Reply With Quote
  #2  
Old June 18th, 2012, 07:15 PM
requinix's Avatar
requinix requinix is online now
Still alive
Dev Shed God 16th Plane (12500 - 12999 posts)
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,863 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 5 Days 5 h 48 m 53 sec
Reputation Power: 8977
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
What if someone uses the name "home"?

Reply With Quote
  #3  
Old June 18th, 2012, 08:25 PM
HDFilmMaker2112 HDFilmMaker2112 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 181 HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 11 h 9 m 44 sec
Reputation Power: 27
Quote:
Originally Posted by requinix
What if someone uses the name "home"?


That won't be permitted, we'll have a blocked list. Basically the users url will be in the DB, and that will be used to pull their profile. When someone chooses their url, it'll be checked for the words we're using to make the site work, and then throw an error if it matches one of those.

Reply With Quote
  #4  
Old June 18th, 2012, 09:00 PM
kicken's Avatar
kicken kicken is offline
Wiser? Not exactly.
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: May 2001
Location: Bonita Springs, FL
Posts: 5,654 kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)kicken User rank is General 37th Grade (Above 100000 Reputation Level)  Folding Points: 2670569 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2670569 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2670569 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2670569 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2670569 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2670569 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2670569 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2670569 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2670569 Folding Title: Super Ultimate Folder - Level 6Folding Points: 2670569 Folding Title: Super Ultimate Folder - Level 6
Time spent in forums: 2 Months 2 Weeks 2 Days 5 h 1 m 44 sec
Reputation Power: 3436
Quote:
Originally Posted by HDFilmMaker2112
That won't be permitted, we'll have a blocked list.


What about future expansion, like if someone is using the name 'contest' and you wanted to use that as the slug for some new contest your hosting?

It would be better to separate them somehow, such as doing /profile/John for user profiles, or /p/John if you want it shorter.

If you do still want to go with that setup though, you might look into RewriteMap, or just rewrite all the urls to something like index.php?slug=blah and inside index.php decide if it is a profile name or a page name.
__________________
Recycle your old CD's, don't just trash them


Spidermonkey Tutorial;

If I helped out out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud

Reply With Quote
  #5  
Old June 18th, 2012, 10:13 PM
HDFilmMaker2112 HDFilmMaker2112 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 181 HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 11 h 9 m 44 sec
Reputation Power: 27
Quote:
Originally Posted by kicken
What about future expansion, like if someone is using the name 'contest' and you wanted to use that as the slug for some new contest your hosting?

It would be better to separate them somehow, such as doing /profile/John for user profiles, or /p/John if you want it shorter.

If you do still want to go with that setup though, you might look into RewriteMap, or just rewrite all the urls to something like index.php?slug=blah and inside index.php decide if it is a profile name or a page name.


Looking in to Rewrite Map... I came up with this.

Code:
RewriteMap pages txt:/pagesmap.txt
RewriteRule ^([A-Za-z0-9_]+)$ /index.php?${pages:$1|NOTFOUND} [PT]
#At this point wouldn't everything be sent to index?page_name_here or a 404 page?
RewriteMap profile txt:/profilemap.txt
RewriteRule ^([A-Za-z0-9_]+)$ index.php?profile=${profile:$1|NOTFOUND} [PT]


How would I add in the profile call though? I guess I need some kind of Rewrite Condition, but I have no idea how to do that. I would need a condition that says if the first rewrite rule returns a NOTFOUND go to the second Rewrite Rule.

EDIT:
What about this:

Code:
RewriteMap pages txt:/pagesmap.txt
RewriteRule ^([A-Za-z0-9_]+)$ /index.php?${pages:$1|profile=$1} [PT]


The problem here is I have an else statement in my pages which show up as the default page if the value doesn't match any of the if/elseif statements.

Last edited by HDFilmMaker2112 : June 18th, 2012 at 10:23 PM.

Reply With Quote
  #6  
Old June 18th, 2012, 10:44 PM
HDFilmMaker2112 HDFilmMaker2112 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 181 HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level)HDFilmMaker2112 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 11 h 9 m 44 sec
Reputation Power: 27
Now that I'm thinking about it some more, redoing the if/else statements with a matching condition probably does make sense:

I would just have to make this:
PHP Code:
/*Account Settings Page*/
elseif($_GET['settings']=="account"){
$switch="content";
$content.='
Account Settings
'
;
}
/*Privacy Settings Page*/
elseif($_GET['settings']=="privacy"){
$switch="content";
$content.='
Privacy Settings
'
;
}
/*Settings Home Page*/
elseif(isset($_GET['settings'])){
$switch="content";
$content.='
Settings
'
;



into something like this:

PHP Code:
/*Account Settings Page*/
elseif($_GET['p']=="settings" && $_GET['edit']=="account"){
$switch="content";
$content.='
Account Settings
'
;
}
/*Privacy Settings Page*/
elseif($_GET['p']=="settings" && $_GET['edit']=="privacy"){
$switch="content";
$content.='
Privacy Settings
'
;
}
/*Settings Home Page*/
elseif($_GET['p']=="settings"){
$switch="content";
$content.='
Settings
'
;



Then rewrite to /settings and /settings/account and /settings/privacy

Doing that it should be as simple as the following, right:

Code:
RewriteRule ^([A-Za-z0-9_]+)/?([A-Za-z0-9_]+)?/?$ /index.php?p=$1&edit=$2


That should match anything between a-Z and 0-9 with an optional / and an optional second "folder" with an optional /.

Last edited by HDFilmMaker2112 : June 18th, 2012 at 10:58 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationApache Development > Rewrite to different kinds of php conditions

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap