Welcome Guest, Not a member yet? Register   Sign In
class name being added/duplicated in url
#1

[eluser]codehound[/eluser]
I am having an issue with the url adding the class name to a link or href.

The src for an img tag is "image/imagename". When I enter the url into a browser (eg. domain/folder/class/function/) the image won't show. When I check the url for the image the url is as follows "domain/folder/class/image/" when it should be "domain/folder/image/imagename".

When I put a href in an a tag (eg. "class/function"), when I hover over the link the url I get is "domain/folder/class/class/function/".

I looked everywhere and I can't find a solution. Is it some server setting I need to change? Do I need to change some codeigniter setting? Or is there some other reason for this behavior.

Any help would be appreciated. Thank you.
#2

[eluser]WanWizard[/eluser]
Your coding relative paths, they are always relative to the URL path, which is "domain/folder/class", and the 'page' requested on that path is 'function'.

Working with relative paths in combination with URI segments should be avoided ("domain/folder/class/function/bla/bla/bla/bla" will still load your controller, but with all assets missing) at all costs. Store all assets in a /assets folder, and use absolute paths.
#3

[eluser]codehound[/eluser]
I have my website in a folder in the server root folder. I am also using .htaccess to remove index.php from my url.

All the codeigniter files are in the system folder and all assets are in separate folders (eg. all images in an images folder). When I enter the base url of the website all assets show up properly but when I enter the controller class name after the base url the assets don't load. The controller's class name keeps being added to the url if I click a link on the page.

eg. "domain/folder/" - original url
"domain/folder/class/" - after clicking link
"domain/folder/class/class/" after clicking link again...

etc, etc.

What is causing this issue?
#4

[eluser]WanWizard[/eluser]
You are using relative paths!

Make sure the base_url in config/config.php is set to 'domain/folder', then use
Code:
<img src="&lt;?php echo base_url(); ?&gt;/images/myimage.jpg" />
#5

[eluser]InsiteFX[/eluser]
Or you can use the HTML Helper img.

HTML Helper

InsiteFX
#6

[eluser]codehound[/eluser]
I found a way to keep relative links and get everything working properly.

I used the html base tag.

Thanks for all the suggestions and help.




Theme © iAndrew 2016 - Forum software by © MyBB