Feature (done?)

discussing clean urls / #2267

Summary

v0.08
done?
Sep 29, 2006
100%
Sep 29, 2006 / pixtur
Feb 27, 2007 / pixtur
pixtur
 

Attached files

No files uploaded
Some support of clean urls has been implemented. See this link:

Earlier Discussion

Actually the way streber handles pages would very well fit together wit clean urls:

The url:

 http://streber.pixtur.de/index.php?go=taskView?tsk=234

could be written as...

 http://streber.pixtur.de/task/234

or even

 http://streber.pixtur.de/234


Suggestions

from .htaccess

...
RewriteEngine On

RewriteRule ^task/(.*)/$ index.php?go=taskView?tsk=$1 [L]
...


Stay compatible

As mod_rewrite is disabled by default, we should make sure, that streber is working without it. We can add an config-option "USE_CLEAN_URLS" which is been set automatically on fresh installations.

If the admin of a streber installation is sure, that mod_rewrite is installed, he could add the line confChange("USE_CLEAN_URLS",true); to the customize.inc.php.

Retro style links with index.php?go= should still work, even if USE_CLEAN_URLS is true.


Mapping requests

Single Item Ids

http://www.streber-pm.org/123

from .htaccess

RewriteRule ^(d+)/$ index.php?go=itemView?item=$1 [L]

Since every item in streber has a unique ID we detect it's type on the fly. Since all links inside streber are build by $PH->getLink() and $PH->getUrl() changing the link style would be straight forward:
  1. add additional option use_as_item_view to page-handles that are preferred views of items: taskView, effortView, etc.
  2. add wrapperFunction std/class_pagehandler.inc.php -> itemView() that queries the item type by... if($item= DbProjectItem->getVisiblebyId($id)) { $type= $item->type; } and does a mapping to the appropriate view function: $page=$g_handles[$type."View"]; if(isset($page)) { $PH->show($page);}
This would reduce html code and make most urls pretty clean.

Submitting POST data

Each page has a <form> element which is rendered in render/render_page.inc.php:

from render_page.inc.php

$buffer= '<form name="my_form" action="index.php" method="post" enctype="multipart/form-data" >';

When USE_CLEAN_URLS index.php should be renamed to submit or the go parameters inside the POST data.


Other pages

The format of other urls needs some discussion...

 
http://www.streber-pm.org/index.php?go=taskEdit&tsk=234
 might become...
   http://www.streber-pm.org/taskEdit/234
   http://www.streber-pm.org/234/edit
   http://www.streber-pm.org/234/edit/format=pda

   
http://www.streber-pm.org/index.php?go=projViewTasks&prj=2&preset=my_open
 might become...
   http://www.streber-pm.org/2/viewTasks/preset=my_open
   http://www.streber-pm.org/2/viewTasks/my_open

http://streber.pixtur.de/index.php?go=taskEditDescription&tsk=2267&from=b0023237383c29ff6b7fdb20a5fa7061
 might become...
   http://streber.pixtur.de/2267/editDescription/from=b0023237383c29ff6b7fdb20a5fa7061


15 Comments

tino

Sep 30, 2006
we could do this with...
mod_rewrite

This solution would be quite cool

binder

Sep 30, 2006
mod_rewrite is your friend
but we have to add some way to get the variables out of the url and to write these urls. I can write some more on this issue next week.

pixtur

Sep 30, 2006

pixtur

Oct 13, 2006
hi binder...
Any updates on this one? I am very interessted in that feature...

pixtur

Oct 24, 2006
implemented some part but...
I am very happy with the implementation of the first step. Sometimes programming is fun. Actually I just had to adjust the Pagehandler->getUrl() function and provide information for each pagehandle on how it should be rendered as a clean url. Like...

from pages/_handles.inc.php

new PageHandle(array('id'=>'taskView',
    'req'=>'pages/task_view.inc.php',
    'title'=>__('View Task'),

    'test'=>'yes',
    'test_params'=>array('tsk'=>'_taskView_',),

    'cleanurl'=>'_ITEM_',
    'cleanurl_mapping'=>array('tsk' => '_ITEM_'),

));

When requesting urls from the Page handler it checks if the requested page id has a cleanurl setting and if USE_MOD_REWRITE is enabled. Then he goes through the parameters and cleanurl_mapping and replaces all mapped varibable occurences in the cleanurl.

Problem:

  • What seems to be tricky is the rendering of multiple attributes like:

 www.pixtur.de/23/tasks

Although I could parse this somehow, after building the new page, all urls to items (which where perfectly valid before) like="24" now point to "23/24" just as if 23 would be a real directory. I am stuck with this and need some help of an Apache guru ,-)


pixtur

Nov 13, 2006
I would consider to be complete...
Maybe we sould write some documentation for it.

madlyr

Nov 13, 2006
I love this stuff and all urls should be 'cleaned' :-)
I use it just from moment I saw it on streber site :-) I think all urls' shoould be filtered and cleaned.

madlyr

Nov 13, 2006
version 2
'clean url' vs. SEF (Search Engine Friendly)
In Mambo / Joomla this has much better name SEF - Search Engine Friendly urls. It is woth of note OpenSEF module to Joomla here.

Yes it doesn't matter if something useful is named A or B but for a lot of people clean url will be new name, SEF is much more known in php environment :-)

Just my 2 cents :-).

madlyr

Nov 13, 2006
Problem with trailing /
Still there is problem to get worked clean urls ending with trailing /.

http://streber.pixtur.de/2647 works good, but http://streber.pixtur.de/2647/ is not working.

I see in .htaccess some rules about this, I checked some rules form Joomla but still I didn't get proper results. It is important to get trailing "/" working.

madlyr

Nov 13, 2006
submit at end of url after editing something
If you edit task and get submit, then we go to the task page with url suffix /submit. Any refresh of this page gives problem, bookmarking page gives problem (bookmark http://streber.pixtur.de/submit and see this error).

I think after submitting anything we should reload page or rewrite page url that page does not contains submit suffix.

Only form url or directly submitting using get parameters should contain submit suffix.

pixtur

Nov 14, 2006
Regarding Submit problem and more Clean urls...

Naming

Well, I don't care how this is called. If you google...
  • "clean urls" - 1.290.000 results
  • "Search Engine friendly urls" : 2.350.000 results
You won :)

More Urls

I would very much like to have more SEFUs but I just didn't get it to work. Somehow the browser got the "/32" as a new subdir and failed loading the stylesheets. Maybe I am just too stupid, but after some hours, I just didn't care anymore...

I would love, if you could give it a try...

Do you need any more documation to the code?

Submit bug...

I already noticed this bug a lot of times and will fix this behavior.

madlyr

Nov 17, 2006
Yes please add some more nfo

from cite

More Urls
I would very much like to have more SEFUs but I just didn't get it to work. Somehow the browser got the "/32" as a new subdir and failed loading the stylesheets. Maybe I am just too stupid, but after some hours, I just didn't care anymore...

I would love, if you could give it a try...

Do you need any more documation to the code? 

Yes I do, please.

pixtur

Dec 11, 2006
I put it on my todo list...
sorry for being too slow at the moment

deizel

Feb 26, 2007
Joomla! 1.5
You guys might want to have a look at what Jinx has come up with before you go implementing human readable URIs.

http://forum.joomla.org/index.php/topic,140836.msg687957.html#msg687957

pixtur

Feb 27, 2007
Antwort auf Joomla! 1.5
I will have a look at it. Thanks.


 

Comment / Update