<![CDATA[ Url rewrite or Friendly url - MODX Community Forums]]> https://forums.modx.com/thread/?thread=104993 <![CDATA[Url rewrite or Friendly url]]> https://forums.modx.com/thread/104993/url-rewrite-or-friendly-url#dis-post-564539
On many modern sites I see this pattern, but haven't figured out how to do it with modx yet.

Say I have a user who clicks on a link on Facebook with the following url: mysite.com/event/3rf78gh9 they will, with my mod_rewrite rule hit a page more commonly known as

index.php?id=23&eventId=3rf78gh9


This works with the following Rewrite_rule.

RewriteRule ^event/([^/]+)/?$ event/?eventId=$1 [L]


My scenario is of cause a bit more complex then this, and I would really like to be able to also do the following:
index.php?id=24&eventId=3rf78gh9

Which should translate to
mysite.com/event/3rf78gh9/messages

Where id 24 is messages

However i can't figure out how to create that type of mod_rewrite rule, please come up with suggestions for this.

Now being a perfectionist I would also like to have my links generated with the same rules. Eg.
[[~24 &eventId=`3rf78gh9`]]


Is it even possible with modx
Best
Moonkin


]]>
moonkin_dk Mar 21, 2019, 10:26 PM https://forums.modx.com/thread/104993/url-rewrite-or-friendly-url#dis-post-564539
<![CDATA[Re: Url rewrite or Friendly url]]> https://forums.modx.com/thread/104993/url-rewrite-or-friendly-url#dis-post-564604
I think that is the way I'll be going, Thanks for taking the time to look at the this.

Best
Moonkin]]>
moonkin_dk Mar 26, 2019, 08:21 AM https://forums.modx.com/thread/104993/url-rewrite-or-friendly-url#dis-post-564604
<![CDATA[Re: Url rewrite or Friendly url]]> https://forums.modx.com/thread/104993/url-rewrite-or-friendly-url#dis-post-564549
[[CreateUrl? &docId=`24` &eventId=`3rf78gh9`]]



/* CreateUrl snippet */
return MODX_BASE_URL . 'event/' . &eventId . '/messages.html';



You didn't have '24' in your example URL, so I didn't know what to do with it in the code.


]]>
BobRay Mar 22, 2019, 05:19 PM https://forums.modx.com/thread/104993/url-rewrite-or-friendly-url#dis-post-564549
<![CDATA[Re: Url rewrite or Friendly url]]> https://forums.modx.com/thread/104993/url-rewrite-or-friendly-url#dis-post-564547
I solved the mod_rewrite rules, so that is no longer an issue.
If anyone is looking to do something similar here's the rules:
RewriteRule ^event/([A-Za-z0-9-]+)/?$ event/?eventId=$1 [N]
RewriteRule ^event/([A-Za-z0-9-]+)/messages.html$ event/messages.html?eventId=$1 [L,QSA]


Second part is still up in the air.

How would one have
[[~24 &eventId=`3rf78gh9`]]

//Be parsed to 
event/3rf78gh9/messages.html


I think I could create a small snippet for writing the urls, but is there another way?

Best
Moonkin]]>
moonkin_dk Mar 22, 2019, 03:49 PM https://forums.modx.com/thread/104993/url-rewrite-or-friendly-url#dis-post-564547