<p>So from reading your updated answer and looking at the <a href="https://craftcms.stackexchange.com/questions/9986/is-it-possible-to-route-to-www-site-com-username/9992#9992">other question you mentioned</a> I would assume you are trying to create prefixed dynamic links that don't conflict with your routing.</p>

<p>For example <code>site.com/about</code> would link to your about page and <code>site.com/#about</code> would load up your custom template.</p>

<p><strong>Problem</strong></p>

<p>The problem with using a <code>#</code> for your trigger is that really this should be used for linking to internal sections on a page and with the above <code>site.com/#about</code> would actually just link to your index page and if you had a <code>&lt;div&gt;</code> with an id of <code>about</code> you'd find the scroll position at that div, so I think using a <code>#</code> is going to give you a lot of headaches.</p>

<p><strong>Solution</strong></p>

<p>Perhaps use the <code>@</code> sign? if it's good enough for twitter to use then I don't think you'll have many problems using it.</p>

<p>So, in your <code>config/routes.php</code> you would have:</p>

<pre><code>return array(
 '(?P&lt;username&gt;\@\w+)' =&gt; '_someCustomTemplate',
);
</code></pre>

<p>This will match anything starting with an <code>@</code>, assign it to <code>username</code> a variable in your template and load it up, I tested on the Happy Lager install and it worked like a charm, <code>/about</code> goes to the about page <code>/@about</code> goes to my custom template</p>

<p>So in your custom template you could have the following:</p>

<pre><code>{# This will get rid of the @ #}
{% set username = username|replace({'@': ''}) %}

{% set user = craft.users.username(username) %}
</code></pre>

<p>If you want to change the trigger to something else, just change <code>@</code> in the route expression and then in the replace filter, but that should do the trick for you and avoid conflicts!</p>

<p><em>on a side note, I replaced <code>@</code> with a <code>#</code> and it didn't work, just went to the home page</em></p>

CC BY-SA 3.0
2015-06-05T07:21:41.810Z
2015-06-05T07:54:17.377Z
2017-04-13T12:51:00.303Z
Alec Ritson
<p>The goal is to have a <strong>variable</strong>(link) merged with prefix "any special character", that will not break the URL(<em>this was pointed to my about character in URL lately, but in this question, We use "#")</em>. So the final output would be "site.com/#variable" (in my case it is the author of an entry and a link to author's profile. </p>

<p>Also, I'd have to route it to get the correct template loaded. The whole reason behind is, that the current prefix would avoid of potential conflicts with other templates in case, some username will be 'index'.</p>

CC BY-SA 3.0
2015-05-26T15:02:47.117Z
"linkToLeft" is already different from "linkToRight"?
carlcs
CC BY-SA 3.0
2015-05-26T15:07:30.387Z
Understand this as "link" is variable and "ToLeft" and "ToRight" are two different links of type. Both serve different type of content. To you question, Yes it's already different.
Dominik Krulak
CC BY-SA 3.0
2015-05-26T15:49:06.040Z
I'm not sure I'm following `"link" is variable and "ToLeft" and "ToRight" are two different links of type.`.  Maybe edit the original question with some further clarification?
Brad Bell
CC BY-SA 3.0
2015-05-26T16:40:09.570Z
Hope, the question's update will help.
Dominik Krulak
CC BY-SA 3.0
2015-05-26T17:20:13.527Z
Where does the "toLeft" and "toRight" go in the final link? And I still don't get it, why do you want to prefix it with a "#"? They are already different!
carlcs
CC BY-SA 3.0
2015-05-26T17:35:02.270Z
It doesn't matter where it goes. What matters is, what template gets loaded. The reason Why I defined the links with "ToLeft" and "ToRight" is, that both represent different types of content, which require two different templates. If I would want to set the route in CP for both links, It would looks like `*` loads "_ToLeft" and `*` loads "_ToRight" template. This would not work. So I think, the special character would actually help here.
Dominik Krulak
CC BY-SA 3.0
2015-05-27T11:52:07.800Z
The _hashtag_ denotes a URL fragment and will essentially break your URL at the insertion point - as such, it's probably a poor choice of special character. More to the point, how are the two types of content different? Are they different entry types or the like? A decent way to solve this would be to point both URLs to the same, generic template, where you include the specific template based on the content - eg {% include entry.type ~ '-partial' %}
Mats Mikkel Rummelhoff
CC BY-SA 3.0
2015-05-27T13:18:27.320Z
Authors and entries. These are the content types.  Doing it this way, I wouldn't achieve a special character in the link. The question is unclear and I don't know How more precisely to clarify it for others, so I've proposed to close it.
Dominik Krulak
CC BY-SA 3.0
2015-05-27T15:05:15.997Z
Is the idea that if you had two urls like `#author1linkToRight` and `#author1linkToLeft` you would be able to separate the `#author1` and `linkTo...` parts based on whether it has the special character prefix? So then you'd have two variables, `#author1` and `linkTo...` that you'd be able to use to pull the correct template in?
Alec Ritson
CC BY-SA 3.0
2015-06-02T20:08:36.333Z
Kind of not @Alec Ritson. I updated the question and it may link a little bit to [this question](http://craftcms.stackexchange.com/questions/9986/is-it-possible-to-route-to-www-site-com-username/9992#9992)
Dominik Krulak
CC BY-SA 3.0
2015-06-04T13:58:25.143Z
If this gets reopened i'm 99% sure I have a solution...
Alec Ritson
CC BY-SA 3.0
2015-06-05T06:24:32.013Z
@AlecRitson Go for it :)
Lindsey D
<routes>
Is it achievable to route a dynamic URI with prefixed character?
# Is it achievable to route a dynamic URI with prefixed character?

(Asked by: username_0 on 2015-05-26)

The goal is to have a **variable**(link) merged with prefix "any special character", that will not break the URL(*this was pointed to my about character in URL lately, but in this question, We use "#")*. So the final output would be "site.com/#variable" (in my case it is the author of an entry and a link to author's profile.

Also, I'd have to route it to get the correct template loaded. The whole reason behind is, that the current prefix would avoid of potential conflicts with other templates in case, some username will be 'index'.

**Tags:** routes

> **Comments:**
> **username_1**: "linkToLeft" is already different from "linkToRight"?  
> **username_0**: Understand this as "link" is variable and "ToLeft" and "ToRight" are two different links of type. Both serve different type of content. To you question, Yes it's already different.  
> **username_2**: I'm not sure I'm following `"link" is variable and "ToLeft" and "ToRight" are two different links of type.`.  Maybe edit the original question with some further clarification?  
> **username_0**: Hope, the question's update will help.  
> **username_1**: Where does the "toLeft" and "toRight" go in the final link? And I still don't get it, why do you want to prefix it with a "#"? They are already different!  
> **username_0**: It doesn't matter where it goes. What matters is, what template gets loaded. The reason Why I defined the links with "ToLeft" and "ToRight" is, that both represent different types of content, which require two different templates. If I would want to set the route in CP for both links, It would looks like `*` loads "_ToLeft" and `*` loads "_ToRight" template. This would not work. So I think, the special character would actually help here.  
> **username_3**: The _hashtag_ denotes a URL fragment and will essentially break your URL at the insertion point - as such, it's probably a poor choice of special character. More to the point, how are the two types of content different? Are they different entry types or the like? A decent way to solve this would be to point both URLs to the same, generic template, where you include the specific template based on the content - eg {% include entry.type ~ '-partial' %}  
> **username_0**: Authors and entries. These are the content types.  Doing it this way, I wouldn't achieve a special character in the link. The question is unclear and I don't know How more precisely to clarify it for others, so I've proposed to close it.  
> **username_4**: Is the idea that if you had two urls like `#author1linkToRight` and `#author1linkToLeft` you would be able to separate the `#author1` and `linkTo...` parts based on whether it has the special character prefix? So then you'd have two variables, `#author1` and `linkTo...` that you'd be able to use to pull the correct template in?  
> **username_0**: Kind of not @username_4. I updated the question and it may link a little bit to [this question](http://craftcms.stackexchange.com/questions/9986/is-it-possible-to-route-to-www-site-com-username/9992#9992)  
> **username_4**: If this gets reopened i'm 99% sure I have a solution...  
> **username_5**: @AlecRitson Go for it :)  

---

## 1 answers

### Answer by username_4 on 2015-06-05. Score: 4 | Accepted answer

So from reading your updated answer and looking at the other question you mentioned I would assume you are trying to create prefixed dynamic links that don't conflict with your routing.
For example site.com/about would link to your about page and site.com/#about would load up your custom template.
Problem
The problem with using a # for your trigger is that really this should be used for linking to internal sections on a page and with the above site.com/#about would actually just link to your index page and if you had a  with an id of about you'd find the scroll position at that div, so I think using a # is going to give you a lot of headaches.
Solution
Perhaps use the @ sign? if it's good enough for twitter to use then I don't think you'll have many problems using it.
So, in your config/routes.php you would have:
return array(
 '(?P\@\w+)' => '_someCustomTemplate',
);

This will match anything starting with an @, assign it to username a variable in your template and load it up, I tested on the Happy Lager install and it worked like a charm, /about goes to the about page /@about goes to my custom template
So in your custom template you could have the following:
{# This will get rid of the @ #}
{% set username = username|replace({'@': ''}) %}

{% set user = craft.users.username(username) %}

If you want to change the trigger to something else, just change @ in the route expression and then in the replace filter, but that should do the trick for you and avoid conflicts!
on a side note, I replaced @ with a # and it didn't work, just went to the home page


---

