Skip to main content
Topic: SEF URLs .. Yes I know it's been discussed (Read 17791 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Re: SEF URLs .. Yes I know it's been discussed

Reply #30

Quote from: ahrasis – That part is quite easy in Nginx. But others, I am not so sure.
Well .. the PHP code itself is very complexe ..
But .. the most entrys can be done with hooks.

Fel
Many are stubborn in relation to the path, a few in relation to the target.
Visit our new Forum Project on https://www.portamx.com

Re: SEF URLs .. Yes I know it's been discussed

Reply #31

Hi Feline, can´t you write the SEF Mod for Elkarte or do you want to keep this just for your own PortaMX forum ?


Re: SEF URLs .. Yes I know it's been discussed

Reply #32

I don't write code for Elkarte ... only for our Forum version.
Many are stubborn in relation to the path, a few in relation to the target.
Visit our new Forum Project on https://www.portamx.com

 

Re: SEF URLs .. Yes I know it's been discussed

Reply #33

Let's use that just because it's the first topic that came up from the search.
Today I started[1] playing with semantic urls.

The current progress is this one:
https://github.com/elkarte/Elkarte/compare/development...emanuele45:semantic_urls?expand=1

The general idea is:
  • Url_Generator stores all the possible alternative "url generators",
  • "Standard" is the normal one, no whistles, current ?topic=123 etc. and it will be the default fallback in case a "type" of URL is not known (I'm not entirely sure if this feature is actually needed, but it seemed fit into the design, so I added it, or maybe at the time I was thinking to use it differently... who knows.),
  • the semantic URLs will be created by another class, and in case something "special" is required, it can be dealt with by adding new types.

The way the code works should be somehow easy I think, I created a function that calls the singleton (yeah, again, I know, I just didn't know where to put the darn stuff, so for the time being I stuffed it in a singleton that looks nicer that $context to me, at least for this kind of things).
The example I used is:
Code: [Select]
'url' => $scripturl . '?action=markasread;sa=all;bi;' . $context['session_var'] . '=' . $context['session_id']
that becomes:
Code: [Select]
'url' => getUrl('action', array('action' => 'markasread', 'sa' => 'all', 'bi', $context['session_var'] => $context['session_id']))
I'm pretty sure purist of speed will frown at the fact it needs a function call... feel free to stick with your buffer rewrite. :P

Of course, this is just the easy part, now the two difficult ones:
  • parse the GET,
  • replace all the URLs in the code base

And since 2 is massive, I decided to post it here to get some feedback regarding the code, if anyone sees problems or lacks of features, because I would like to avoid having to redo everything two times. O:-)
well, it's not true because the code was laying around since quite a while and it was not even committed, so I've been quite lucky I didn't delete it while doing some cleaning. xD
Bugs creator.
Features destroyer.
Template killer.

Re: SEF URLs .. Yes I know it's been discussed

Reply #34

Quick look I think its good

May want to consider moving the session var and id stuff to the getUrl() function, maybe as a third param done as true/false.  True by default with an false option not to add it (I guess that may be needed somewhere maybe?)

Re: SEF URLs .. Yes I know it's been discussed

Reply #35

Good point.
Maybe, though, false by default, I think the number cases we do not want session is far greater than when we want it?
I'll try to get some number later.
Bugs creator.
Features destroyer.
Template killer.


Re: SEF URLs .. Yes I know it's been discussed

Reply #37

Getting all fancy on me ... I like it !

Re: SEF URLs .. Yes I know it's been discussed

Reply #38

Any idea why in certain list where the url is sprintf'ed, $scripturl has an strtr to replace single % to %%?
Code: [Select]
'format' => '<a href="' . strtr($scripturl, array('%' => '%%')) . '?action=profile;u=%1$d">%2$s</a>',
Bugs creator.
Features destroyer.
Template killer.

Re: SEF URLs .. Yes I know it's been discussed

Reply #39

I kind of found my answer. It was randomly applied in few places during the very first implementation of createList, but apparently without any real schema: in certain places it was added, in others it was not.
So, unless anyone has any objection, I'm going to drop them all and go for the "without strtr" version.
Bugs creator.
Features destroyer.
Template killer.

Re: SEF URLs .. Yes I know it's been discussed

Reply #40

Okay, few months after I have the prototype up and working locally.
It doesn't come with any configuration yet (not even the "enable") is not yet completed because I replaced only the potentially bot-facing urls in the controllers and subs (still have to touch the template) and is probably buggy, but it's a start.
I went for:
index.php?b/{boardname}-{id}/page-{number}
index.php?t/{subject}-{id}/page-{number}
* index.php?p/{username}-{id}
and then after that a question mark and any other parameter.

It's yet another re-inventing the wheel kind of thing, but... well, it was easier for now to write it rather than learn how to use existing stuff. xD

Here it is the code:
https://github.com/elkarte/Elkarte/compare/development...emanuele45:semantic_urls?expand=1

When the templates will be done I'll send the pull request. If anyone is interested in helping with this, it may do with some testing (and a working example of htaccess to hide the index.php? part would be very helpful! xD), and if you are interested enough to do some coding, you can send PRs to my own repo. ;)
Bugs creator.
Features destroyer.
Template killer.

Re: SEF URLs .. Yes I know it's been discussed

Reply #41

There:
https://github.com/elkarte/Elkarte/pull/3246

Many things are missing, but at least something is there. xD
Bugs creator.
Features destroyer.
Template killer.

Re: SEF URLs .. Yes I know it's been discussed

Reply #42

I've been preaching SEF url's for years...its the only reason I keep going back to the not ready for prime time Vanilla software.  If Elk had SEF url's it would be the "bees knees" as I think they say over in jolly ol' England. 

Code: [Select]
# sef engine
RewriteBase /forum/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

This seems to work in cleaning up the URL's to my forum. 
Got rid of: /index.php?PHPSESSID=80b4efc14c62366ebf046e6bd9d6d09d&board=12.0

The URL's are not as good as "/welcome-to-our-forum"  but better then it was!   Is it OK to use this?
Last Edit: November 05, 2018, 04:45:53 pm by elk_is_cool

Re: SEF URLs .. Yes I know it's been discussed

Reply #43

Quote from: Jorin –
Quote from: Feline – @emanuele known the code .. she is the right person to implement that for elkarte (I think)  ;)

FYI she is a he.  :D

That had me confused too.   I was looking at Emanuele's avatar, and thought, if that's a female avatar, we're in trouble!   :o

Re: SEF URLs .. Yes I know it's been discussed

Reply #44

Emanuele is male. Read again please.  ;)