Don't understand CI urls, adding prefix to my urls - php

I have the following link:
<li>Dogs</li>
In my config.php I have:
$config['base_url'] = '127.0.0.1/Won/';
And when I go to link on that link above, it points to this:
http://127.0.0.1/Won/127.0.0.1/Won//gallery/dogs
Yes I have tried to search for a solution to this prior to asking.

Your base url is set as:
127.0.0.1/Won/
Your html anchor uses this code for the href:
<?php echo base_url() ?>/gallery/dogs
If you inspect the DOM using your browsers developer tools you should see that your href is being set as:
127.0.0.1/Won//gallery/dogs
To solve this you need to change your configs base url to the following:
http://127.0.0.1/Won/
You also need to remove the extra forward slash from your anchors href code. The correct code would be:
<li>Dogs</li>

Related

Generating url in laravel

I have a problem with url in Laravel
<td> Website: {{$data[0]->internet}}</td>
where internet is some website name, for example www.foo.com
The problem is that output URL is http://localhost/www.foo.com instead of http://www.foo.com
change the target attribute target="blank" to target="_blank"
Change your html to
{{$data[0]->internet}}
As stated in the Laravel documentation: https://laravel.com/docs/5.7/urls
The url helper may be used to generate arbitrary URLs for your
application. The generated URL will automatically use the scheme (HTTP
or HTTPS) and host from the current request
$post = App\Post::find(1);
echo url("/posts/{$post->id}");
// http://example.com/posts/1
In your case you won't need the url helper function.
Also make use of the http or https protocol in this format:
http://www.foo.com or https://www.foo.com to make an absolute url instead of a relative one.
Try this way:
{{$data[0]->internet}}
If your variable internet is some website name, for example
www.foo.com and you need to link this URl in anchor tag you dont need
to call this variable inside url() function you can simply use that
variable to link the url in anchor tag.
If you want to get the base URL of your site then you can use url()
fucntion which return base url of your website.
Just replace below line with your code
<td>
Website:
{{$data[0]->internet}}
</td>

Anchor HREF, if I click again the anchor the link on the address doubles or it concatenate on the existing link. What's the best way to avoid this?

Good Day! I've got some trouble on PHP. If I click an href which is this <a href = 'members/loans/loan-application-form.php'> it goes to the loan-applicaton-form.php, but if i click it again inside the loan-application-form.php (cuz it is located at the navbar that exist in all pages) the href of the anchor concatenates on the existing url and it creates an error telling that address is not existing. I already knew that the problem is it searches the address on the current directory and probably it will return an error because there is no existing address on the directory because it is the origin or the parent. What is the best way to avoid this?
Add a base tag to your header. This will prepend all HTML URL's with the given base URL. (Including images, CSS and JS calls)
<head>
<base href="http://www.yourdefaulturl.com/">
</head>
Your URL will then be http://www.yourdefaulturl.com/members/loans/loan-application-form.php
You can use an absolute path
<a href = 'http//your.site.cpm/members/loans/loan-application-form.php'>
Advice : you can read this article
or this stack question
Or you can use ../ to navigate inside your relative path
Lets imagine your nav bar is located at /navigation/navbar.html
Then you can have a relative path like
<a href = '../members/loans/loan-application-form.php'>
By specifying relative Urls like so:
<a href = 'members/loans/loan-application-form.php'>
You are simply stating you wish to go form the current page to this page, hence why it is being added to the end of the current URL. The best way to avoid this quite simply is to set an absolute URL like so:
<a href = 'http://projectname/members/loans/loan-application-form.php'>
Even when not using http:// it is often still considered relative so be sure to include this.
Another way to do the same but slightly quicker would be to add a variable in say your header file for example:
$url = 'http://example.com';
Then when specifying the URLs you can do say:
<a href = '<?php echo $url;?>/members/loans/loan-application-form.php'>
This just means that should you say change your domain, rather than editing every URL you can simply edit the variable value and be done with it.

URL base changing after using any controller with parameters

i'm having an problem with the URL of Codeigniter.
When i use one controller with parameter, example: localhost/ci/products/news (where localhost/ci is the url base), after i click in any element <a />, example: <a href="home"/> Codeigniter redirects for localhost/ci/products/home and no for localhost/ci/home.
Anyone know why this happens?
You must use a base_url for links. Right now your anchor has a relative path in the href="home", you should have full path in your links, when u use mod_rewrite for nice urls.
like
Home

Can I modify anchor tag href in htaccess?

Not sure if this is possible but wanted to know if htaccess has a trick...
Say I have anchor tag href like this -
Click here
I have changed the URL structure using mod_rewrite but wanted to know if i can hide the actual URL in href using htaccess.
i.e when a user hover over the anchor tag, the browser displays http://example.com/index.php?id=12345 at the bottom. All I want the browser to display is http://example.com/index/12345 without changing it manually on all my pages.
Thanks for the help !
Why don't you change the link to the following?
Click here
As you can change the .htaccess I expect that you own or adminstrate this domain. So it should be possible.
If the links are generated by PHP code, then I suggest you to implement and use a translation function like:
function beautify($ugly) {
// your logic comes here
return $nice; // ;)
}
... and wrap it around the existing code that currently outputs the urls. This would have two advantages:
It's easy and more failsafe to migrate to the new url scheme
From now on you have control over all url related code using a single function
I agree, htaccess can't help you. I guess you'll have to change them manually.
I wish I could be of more help
No. htaccess is for processing input to the web server, not data sent back from the server.
If you use jQuery you could have it rewrite the href when the page loads using something like this.
$(function(){
$("a").each(function() {
this.href = 'some_new_url that you made based on the one in this.href';
});
});

codeigniter: why is that when i echo base_url() in an href attribute of an anchor tag, it echoes twice

so basically when i echo the codeigniter function base_url() in the href attribute of an anchor tag, it appears to echo it out twice. Example:
somelink
and the above, if you inspect it your chrome browser shows this:
somelink
"mysitedomainname.com" is just a name i made up for this example. Any reason why this is happening?
There are three reasons I'm aware about that can cause this.
The first one is when something wrong is written in config.php on line 17 $config['base_url'] = ''; - it better be left empty, just like when you download CI.
The second one is if you have set $config['base_url'] value to something without prefixing it with http:// or other protocol.
The third one is if you have set base href somewhere:
<base href="http://www.mysitedomainname.com/" />
When you need to link to some other page, you should use site_url(), base_url() can be used to link stylesheets, js, img src attributes and other real URL's. The reason is pretty simple, base_url() does not include the index_page value set in config.php.
try this
make this
$config['base_url'] = "http://www.mysitedomainname.com"
into this
$config['base_url'] = ""
in config.php
It will work fine if you use
somelink

Categories