News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

SMF Replacing my a href's?

Started by Jackool, March 26, 2015, 11:46:11 PM

Previous topic - Next topic

Jackool

Hello. This is my first post on this SMF forum after joining back in 2012. Never had any issue with SMF up until now.

I am creating a new theme that includes a navbar with links to various other parts of our website. It seems that SMF is replacing my URL location (href) to a version with the board URL.
Here is an example of what I mean by this...

In my theme's code, I have this inside of index.template.php - which provides links to other non-forum parts of our website


<ul class="nav navbar-nav">

<li><a href="/">Home</a></li>
<li><a href="/donate">Donate</a></li>
<li><a href="/events">Events</a></li>
<li><a href="/market">Market</a></li>
<li><a href="/stats">Stats</a></li>
<li><a href="/bans">Bans</a></li>
<li><a href="/apps">Staff</a></li>
<li class="current-menu-parent"><a href="/forum">Forum</a></li>

</ul>


But, when I view the forum - the href changes to include the boardurl like so


<ul class="nav navbar-nav">

<li><a href="http://devolved.us/forum//">Home</a></li>
<li><a href="http://devolved.us/forum//donate">Donate</a></li>
<li><a href="http://devolved.us/forum//events">Events</a></li>
<li><a href="http://devolved.us/forum//market">Market</a></li>
<li><a href="http://devolved.us/forum//stats">Stats</a></li>
<li><a href="http://devolved.us/forum//bans">Bans</a></li>
<li><a href="http://devolved.us/forum//apps">Staff</a></li>
<li class="current-menu-parent"><a href="http://devolved.us/forum//forum">Forum</a></li>

</ul>


How can I prevent my href's from changing on the live website?
I don't want to change it to "../market" to go back a directory or the full URL like "http://devolved.us/market" because that's just horrible for updates, changing domains, etc.

Kindred

Well of course it is... the browser automatically inserts the main url of the domain in front of the relative.

It is doing exactly what it is supposed to.

You either need to define the full url or the full relative url, using ../

There is nothing else that you can do.
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Jackool

Quote from: Kindred on March 27, 2015, 12:30:39 AM
Well of course it is... the browser automatically inserts the main url of the domain in front of the relative.

It is doing exactly what it is supposed to.

You either need to define the full url or the full relative url, using ../

There is nothing else that you can do.

Uh? You fail to see the issue I am having. The browser does not do what you are saying. I use this same method in ALL my websites. An example of correct behavior:

When the link is clicked it brings you to the base directory of my domain.

It's obviously something SMF's code or default theme is doing. How do I know this? Because the navbar literally include's a PHP file in another directory, viewable here:
hxxp:devolved.us/core/navbar.php [nonactive]

When you view the source of this PHP document, IT IS DOING THE CORRECT THING


<ul class="nav navbar-nav">

<li><a href="/">Home</a></li>
<li><a href="/donate">Donate</a></li>
<li><a href="/events">Events</a></li>
<li><a href="/market">Market</a></li>
<li><a href="/stats">Stats</a></li>
<li><a href="/bans">Bans</a></li>
<li><a href="/apps">Staff</a></li>
<li class="current-menu-parent"><a href="/forum">Forum</a></li>

</ul>


When you click on these links, it should go to the relative BASE DIRECTORY of my domain.

But when THIS SAME FILE is included on my SMF FORUM THEME, the code turns into THIS:

<ul class="nav navbar-nav">

<li><a href="http://devolved.us/forum//">Home</a></li>
<li><a href="http://devolved.us/forum//donate">Donate</a></li>
<li><a href="http://devolved.us/forum//events">Events</a></li>
<li><a href="http://devolved.us/forum//market">Market</a></li>
<li><a href="http://devolved.us/forum//stats">Stats</a></li>
<li><a href="http://devolved.us/forum//bans">Bans</a></li>
<li><a href="http://devolved.us/forum//apps">Staff</a></li>
<li class="current-menu-parent"><a href="http://devolved.us/forum//forum">Forum</a></li>

</ul>


SMF is obviously adding the "http://devolved.us/forum/" through a header or something. THE BROWSER DOES NOT ADD THE DOMAIN INTO MY CODE BY DEFAULT.
I came here to ask what is causing this. It's for sure something in SMF. Using "../" WON'T WORK when in other directories that aren't /forum

This navbar is included in other directories that aren't just /forum - that's why using "/directory" is crucial, so that it's using the base directory when clicking the link.

Kindred

except for the fact that SMF does not do what you are stating...


I am betting that you have an htaccess file in your forum directory that includes a line telling the system to use the forum directory as the base directory


However, the **CORRECT** coding practice would be to use the ACTUAL, DEFINED URL -- not the "/stats"
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

margarett

I made a quick test in my localhost and, in fact, it doesn't add the forum path to it.

My test forum is http://localhost/smf2 and I added

    echo '
    <ul class="nav navbar-nav">
        <li><br class="clear" /></li>
        <li><a href="/">Home</a></li>
        <li><a href="/donate">Donate</a></li>
    </ul>';

under the menu call in index.template.php, eg, after
    // Show the menu here, according to the menu sub template.
    template_menu();

And the resulting links are
http://localhost/
http://localhost/donate

Do you have Pretty URLs installed or any other "url change" MOD?
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Jackool

Quote from: Kindred on March 27, 2015, 06:39:29 AM
except for the fact that SMF does not do what you are stating...


I am betting that you have an htaccess file in your forum directory that includes a line telling the system to use the forum directory as the base directory


However, the **CORRECT** coding practice would be to use the ACTUAL, DEFINED URL -- not the "/stats"
First off, if you are talking about RewriteBase with htaccess - it doesn't magically change the href of URL's on the outputted page.
You should probably create a website and see what it actually does.

How funny, telling me what the correct coding practice for my own website/project should be.
You're wrong. It's not an "incorrect coding practice". Go take a look at hxxp:twitter.com [nonactive] for example, they do the same thing I am stating with URL's:



Don't go around telling people they are using incorrect coding practices when they aren't. When a big company like twitter uses the same method it's obviously not "incorrect practice".
Thanks for trying to help, but you act very cocky in your methods of "help". No wonder your user title states "The Mean One".

Quote from: margarett on March 27, 2015, 09:59:21 AM
I made a quick test in my localhost and, in fact, it doesn't add the forum path to it.

My test forum is hxxp:localhost/smf2 [nonactive] and I added

    echo '
    <ul class="nav navbar-nav">
        <li><br class="clear" /></li>
        <li><a href="/">Home</a></li>
        <li><a href="/donate">Donate</a></li>
    </ul>';

under the menu call in index.template.php, eg, after
    // Show the menu here, according to the menu sub template.
    template_menu();

And the resulting links are
hxxp:localhost/ [nonactive]
hxxp:localhost/donate [nonactive]

Do you have Pretty URLs installed or any other "url change" MOD?

Thank you so much for the extremely useful information. We do use Pretty URLs!

I thought about it and looked through the parse instruction from the PrettyURL addon page and noticed it does rewrite URL's in the PHP code itself, the issue wasn't htaccess like the "team manager" stated.

For anyone else who has this issue (unlikely since it's case-specific), Pretty URLs rewrites the buffer inside of PrettyUrls-Filters.php. On line 259 it replaces the URL's and makes them relative

// Absolutise relative URLs
if (!preg_match('~^[a-zA-Z]+:|@~', $cacheableurl) && !($cacheableurl == '' && isset($fragment[0])) && SMF != 'SSI')
$cacheableurl = $boardurl . '/' . $cacheableurl;


Going to mark this as solved now. Thank you margarett!

Kindred

just one comment (regardless of the silly snark from the OP)

"When a big company like twitter uses the same method it's obviously not "incorrect practice"."

but that is just laughable...
I have worked for several large companies -- and you would not believe how terrible their coding practices are.

nor was I particularly cocky or mean to you...
(and since you never gave the full information (like what mods you were running) I was taking pokes in the dark as to what might be causing it (because, as I stated, a clean installation of SMF doesn't do what you said it was doing)

PrettyURLs would have been my next guess, margarett just beat me to it. :P




See, if you provide half-assed information, you get half-assed answers. :P
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Advertisement: