17 replies [Last post]
roscoe
roscoe's picture
Offline
Enthusiast
Last seen: 11 years 37 weeks ago
Joined: 2006-03-09
Posts: 138
Points: 0

So I have an address that looks something like this: http://www.whatever.com?folder=art_gallery&page=photos

Now I want the user to type in whatever.com/art_gallery/photos and it goes to that address above, but I also want to make it so that if the user just types in: whatever.com/art_gallery it goes to whatever.com?folder=art_gallery&page=index

Is this possible? My knowledge on mod_rewrite is very limited.

Tags:
mihirc
mihirc's picture
Offline
Leader
Pune, Maharashtra, India
Last seen: 5 years 34 weeks ago
Pune, Maharashtra, India
Timezone: GMT+5.5
Joined: 2007-05-09
Posts: 728
Points: 204

hi, i think if u r using

hi,
i think if u r using some kind of CMS then you should search for SEO's(search engine optimization), where it cleans up all the extra tags and makes the pages.html . for ur example it wil might be whatever.com/art_gallery/photos.html

mihir.

Proprietor - Thoughtfulviewfinder Services
Web Development | Design | Merchandise | Photography
My personal blog: MihirChhatre.com

roscoe
roscoe's picture
Offline
Enthusiast
Last seen: 11 years 37 weeks ago
Joined: 2006-03-09
Posts: 138
Points: 0

Problem Solved

I ended up editing the .htaccess file in Apache. This is what I came up with:

RewriteRule ^/?([a-zA-Z_]+)(/([a-zA-Z_]+))?/?$ template.php?folder=$1&page=$3 [L]

It will take something like http://www.whatever.com?folder=folder_name&page=page_name and convert it to http://www.whatever.com/folder_name/page_name

Chris..S
Chris..S's picture
Offline
Moderator
Last seen: 7 years 27 weeks ago
Timezone: GMT+1
Joined: 2005-02-22
Posts: 6078
Points: 173

roscoe: does that gracefully

roscoe: does that gracefully handle your case when only a gallery is specified?

Is $_GET['page'] present, but empty?

mihirc: are you writing your posts with SMS? :?

mihirc
mihirc's picture
Offline
Leader
Pune, Maharashtra, India
Last seen: 5 years 34 weeks ago
Pune, Maharashtra, India
Timezone: GMT+5.5
Joined: 2007-05-09
Posts: 728
Points: 204

SMS?????? NAh!!! I have a

SMS??????

NAh!!! I have a nack of losing cell phones (lost 3 in 3 months).. so i prefer not to have one now... Why did you think so? is the provision available?

mihir.

Proprietor - Thoughtfulviewfinder Services
Web Development | Design | Merchandise | Photography
My personal blog: MihirChhatre.com

burlster
burlster's picture
Offline
Leader
Bournemouth
Last seen: 2 years 26 weeks ago
Bournemouth
Timezone: GMT+1
Joined: 2007-05-31
Posts: 693
Points: 45

My guess would be the

My guess would be the occassional but inconsistent 'sms language'.

"...think if u r using some kind of CMS then you should...". You have abbreviated 'you are' to 'u r' in the first instance, yet we have a full on 'you should' (as opposed to 'u shud') later in the same sentence. The reason I usually do this is when I've written an sms message in perfect English, then realise if I can lose 3 characters from it, it sends as one message thus saving me 10 pence!

That's my theory anyhow Tongue

J

Have YOU said Hello yet?
The CSSCreator Hello Thread

mihirc
mihirc's picture
Offline
Leader
Pune, Maharashtra, India
Last seen: 5 years 34 weeks ago
Pune, Maharashtra, India
Timezone: GMT+5.5
Joined: 2007-05-09
Posts: 728
Points: 204

Guys, i am a active member

Guys,

i am a active member of only one forum (i.e.) this one, while am an active chatter (with friends). so my english vocabulary has been limited to "u r" ... but then "you shud" isnt pleasing to the eye so i avoid using it. Wink

Hey, that was a proper english sentence... :thumbsup:

If you read my blogs, you could say they are a bit better as to my english here (am not saying the blogs are just the english)..

mihir Laughing out loud

Proprietor - Thoughtfulviewfinder Services
Web Development | Design | Merchandise | Photography
My personal blog: MihirChhatre.com

Chris..S
Chris..S's picture
Offline
Moderator
Last seen: 7 years 27 weeks ago
Timezone: GMT+1
Joined: 2005-02-22
Posts: 6078
Points: 173

"u r" isn't pleasing to the

"u r" isn't pleasing to the eye either. Wink

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 5 years 12 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

For the record and to be

For the record and to be blunt but not skirt around the issue :rolleyes:

It is considered bad practise to bring this form of writing to this type of forum, so lets write correctly please Smile

Speeling mistukes alloowed as I can't spell for toffee

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

mihirc
mihirc's picture
Offline
Leader
Pune, Maharashtra, India
Last seen: 5 years 34 weeks ago
Pune, Maharashtra, India
Timezone: GMT+5.5
Joined: 2007-05-09
Posts: 728
Points: 204

Respected Sir's and Madam's

Respected Sir's and Madam's (if any),

I take your bluntness with pride and try and keep my language as technically correct, and please correct me wherever i am wrong. Laughing out loud

Mihir Laughing out loud

Proprietor - Thoughtfulviewfinder Services
Web Development | Design | Merchandise | Photography
My personal blog: MihirChhatre.com

burlster
burlster's picture
Offline
Leader
Bournemouth
Last seen: 2 years 26 weeks ago
Bournemouth
Timezone: GMT+1
Joined: 2007-05-31
Posts: 693
Points: 45

I dnt mnd, bt 4 v gr8r gd,

I dnt mnd, bt 4 v gr8r gd, enuf. Haha, personally I like to delibrately elaborate and use a more extensive vocabulary when I can. I don't bother in this forum though because I read a thread once (I think you were one of the main contributors Hugo) that just made me realise quite how limited my vocabulary actually is. I barely understood a word of half the entries!

Have YOU said Hello yet?
The CSSCreator Hello Thread

mihirc
mihirc's picture
Offline
Leader
Pune, Maharashtra, India
Last seen: 5 years 34 weeks ago
Pune, Maharashtra, India
Timezone: GMT+5.5
Joined: 2007-05-09
Posts: 728
Points: 204

I think you were one of the

I think you were one of the main contributors Hugo) that just made me realise quite how limited my vocabulary actually is. I barely understood a word of half the entries!

Exactly... and thats why i used to use those short cuts though now i wont...

mihir.

Proprietor - Thoughtfulviewfinder Services
Web Development | Design | Merchandise | Photography
My personal blog: MihirChhatre.com

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 5 years 12 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

I can't spell or do the

Smile I can't spell or do the grammar proper but I do have an extensive vocabulary and love playing with words and a proclivity for using them where possible

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

burlster
burlster's picture
Offline
Leader
Bournemouth
Last seen: 2 years 26 weeks ago
Bournemouth
Timezone: GMT+1
Joined: 2007-05-31
Posts: 693
Points: 45

"pro·cliv·i·ty(pr-klv-t) n

"pro·cliv·i·ty(pr-klv-t)
n. pl. pro·cliv·i·ties
A natural propensity or inclination; predisposition."

You knew I'd have to look that up Wink

Have YOU said Hello yet?
The CSSCreator Hello Thread

roscoe
roscoe's picture
Offline
Enthusiast
Last seen: 11 years 37 weeks ago
Joined: 2006-03-09
Posts: 138
Points: 0

Chris..S, yes, it does

Chris..S, yes, it does handle it when only the folder variable is specified and, yes, $_GET['page'] is present and I have an if statement so that if its empty it will then equal "index" which is the default page in the folder. Does that make sense?

Also, I'm not sure if this is the most effective way of doing this so if anyone has any better ideas I would really be interested in hearing more.

//mod edit: Duplicate post was deleted. If anyone got caught up replying to the deleted post, please try again. --gary/kk5st

Chris..S
Chris..S's picture
Offline
Moderator
Last seen: 7 years 27 weeks ago
Timezone: GMT+1
Joined: 2005-02-22
Posts: 6078
Points: 173

Yes, that makes

Yes, that makes sense.

There may be tweaks you can do to your rewrite rules and patterns, apart from that I think you probably on the right track. PHP frameworks (e.g. cakephp) use similar methods to break a url into controller & action and pass it to the single "index.php" script. PHP CMS do something similar for "nice" urls.

Doing everything in one rewrite rule and handling a parameter being empty seems a pretty good way.

thepineapplehead
thepineapplehead's picture
Offline
Guru
Last seen: 2 weeks 4 hours ago
Joined: 2004-06-30
Posts: 9668
Points: 801

burlster

burlster wrote:
"pro·cliv·i·ty(pr-klv-t)
n. pl. pro·cliv·i·ties
A natural propensity or inclination; predisposition."

You knew I'd have to look that up Wink

Blimey, even the definition of the big word is full of big fancy words Tongue

Verschwindende wrote:
  • CSS doesn't make pies

burlster
burlster's picture
Offline
Leader
Bournemouth
Last seen: 2 years 26 weeks ago
Bournemouth
Timezone: GMT+1
Joined: 2007-05-31
Posts: 693
Points: 45

Yeah, but fortunately I knew

Yeah, but fortunately I knew all the words in the definition. It's when I have to research the definition to work out what it means that I give up!!

Have YOU said Hello yet?
The CSSCreator Hello Thread