4 Replies - 1198 Views - Last Post: 11 June 2012 - 01:55 PM

#1 eZACKe  Icon User is offline

  • Garbage Collector

Reputation: 120
  • View blog
  • Posts: 1,278
  • Joined: 01-June 09

Mod Rewrite for variable sized urls

Posted 11 June 2012 - 12:20 PM

So currently I have a mod_rewrite set up to do something like this:
www.example.com/myCmd/myAction
=
www.example.com/?cmd=myCmd&act=myAction

All is well. But not really.

What if I want urls to have any number of slashes?
Like: www.example.com/myCmd/myAction/456/110/Some_Name/
And that might =
www.example.com/?cmd=myCmd&act=myAction&?id=456&page=110&title=Some_Name

But another request on a different page might look like this:
www.example.com/myOtherCmd/myOtherAction/456/110/Some_Name/
And it would translate to =
www.example.com/?cmd=myOtherCmd&act=myOtherAction&?id=456&memberNumber=110&display=Some_Name


So you see, I want a variable number of parameters in the query part of the url, but they don't always have to have the same GET variable.

So is there a mod_rewrite function that can just strip the &'s, ?'s, ='s and names, and just keep the value but I will still be able to use the values like memberNumber, title, etc in my PHP?

Thanks a lot, help on this would be GREATLY appreciated!

This post has been edited by eZACKe: 11 June 2012 - 12:23 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Mod Rewrite for variable sized urls

#2 eZACKe  Icon User is offline

  • Garbage Collector

Reputation: 120
  • View blog
  • Posts: 1,278
  • Joined: 01-June 09

Re: Mod Rewrite for variable sized urls

Posted 11 June 2012 - 12:48 PM

After rereading this and thinking more about what I'm asking, I realize what I'm requesting my actually be imposisble.

But what about this: Can you keep like a counter in mod_rewrite

So I could always convert something like this:
www.example.com/myCmd/myAction/114/118/SOME_NAME....

To

www.example.com/?cmd=myCmd&act=myAction&tmp1=114&tmp2=118&tmp3=SOME_NAME.....&tempx=...
Was This Post Helpful? 0
  • +
  • -

#3 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,991
  • Joined: 08-June 10

Re: Mod Rewrite for variable sized urls

Posted 11 June 2012 - 01:13 PM

I'm curious about one thing... Why are you doing this in the first place? What is the point of rewriting the keys off all the GET values?

Is it to make it "pretty" for the human users? (Do you honestly think they care either way?)

Or is it perhaps some outdated SEO thing? (Which do you think the search engines prefer: having the meta-data or not having the meta-data?)

P.S.
Moved to Web Servers & Hosting. This isn't really a PHP related question.

This post has been edited by Atli: 11 June 2012 - 01:16 PM

Was This Post Helpful? 0
  • +
  • -

#4 eZACKe  Icon User is offline

  • Garbage Collector

Reputation: 120
  • View blog
  • Posts: 1,278
  • Joined: 01-June 09

Re: Mod Rewrite for variable sized urls

Posted 11 June 2012 - 01:17 PM

In all honesty, it really is to make it "pretty" for the human users. Maybe not even so much the human users, but myself. I just like nice looking urls.
Was This Post Helpful? 0
  • +
  • -

#5 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,991
  • Joined: 08-June 10

Re: Mod Rewrite for variable sized urls

Posted 11 June 2012 - 01:55 PM

OK, I see. I won't try to argue with you on that, even though I'm the exact opposite :)
It's just that some people think this is still good for SEO, when it's actually the other way around.

Anyways, the best solution I know of for what you are after is a sort of combo between mod_rewrite and PHP. That is, read the controller and action like you would normally, but then read the remaining parts of the URL into PHP as a single string, and parse it from there using PHP.
RewriteRule ^(\w+)/(\w+)/?(.*) ?cmd=$1&act=$2&params=$3 [L,QSA]


<?php
$params = explode("/", $_GET["params"]);


You can then assign names to the parameters based on the contoller/action pair in any way you see fit. Personally I'd probably just map it out somehow in the constructor of the controller class. (Assuming you're using some kind of OOP MVC pattern.)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1