I need to show to my client the progress of a project that is already in the shared host.
In development, acessing just /localhost/ worked to me, but now that I've sent the files to the host (cPanel), it's breaking in some cases because I need to use the /~cpanelname in the IP. Is there a way to add this /~cpanelname to every URL? After the deployment and insertion of a domain, it will need to be removed also.
The problem basically is:
When I have an image, the src is:
[IP]/img/img.jpg
When it needs to be [IP]/~cpanelname/img/img.jpg
A link href that is /about needs to be /~cpanelname/about
Can you guys help me?
Thanks!
You should be using the asset(), route(), url() etc. helpers to construct all of your links and file references.
If you've done that correctly, you can then change the base URL for all URLs just by changing the config/app.php file's url parameter (typically by changing APP_URL in .env).
Related
I'm developing a Laravel project using wamp stack on windows. My project is located in a separate folder like C:\wamp64\www\[project name]. The annoying problem is with url paths in code. I want to handle them in a way that they work both locally and on production environment.
For example this an absolute link:
<a href="/posts/tags/{{ $tag }}">
It is intended to navigate user to [project name]/posts/... . In other words I want to get project root with a slash. If this is not possible, what is the correct way of handling paths then (on development and production environment). I'm a little confused with this. Please provide detailed information considering both WAMP and Laravel. And please give information about relative paths, too.
You can use url method url method will return base url
edit tag
url()
The url function generates a fully qualified URL to the given path
So what I finally did was to use the suggested method by #iCoders plus having APP_URL set in .env file to http://localhost/[project_name]/public.
This way url method resolves the correct path provided that your config/app.php contains 'url' => env('APP_URL', 'http://localhost') and you make the URL generator use APP_URL. For more information, check this link:
Laravel: Change base URL?
To differentiate development and production environments different .env files can be used for each.
If my root website www folder is /
and the subdomain folder is /subdomain
I can either get to the the address using one of the following
http://subdomain.website.com/
http://www.website.com/subdomain
Now if I access the site using the http://subdomain.website.com, The codeigniter treats the base_url() as http://subdomain.website.com/subdomain is there away of stripping the subdomin from the end if the subdomain segment has the same name?
I could strip it on a case by case basis, but I'm hoping there is a way to do this using one of the system configuration files.
Whatever you are asking, has something to do with setting up dynamic base url in codeigniter. They have been answered here and also here.
Hope you find it helpfull.
I am running a local server on port 4567. I am trying to make it so that when my database seeds I save a reference to the home page on my site in my db. However I noticed when I run URL::to('/') in my seeds it only includes "localhost" without the port, but if I include it in my view code it comes out as "localhost:4567". Why is this? How can I fix it, if possibly, without writing if statement conditionals about what production environment I am in? Thank you.
Seed File result of URL::to('/')
http://localhost
View File result of URL::to('/')
http://localhost:4567
Either set APP_URL in env file
APP_URL=http://localhost:4567
Or set url in config/app.php
'url' => env('APP_URL', 'http://localhost:4567'),
Many internal functions and third-party libraries use the APP_URL .env var directly or via config('app.url'). The better way is to use the URL generator classes that Laravel provides, eg. the Url facade.
Even so, you'll see different results in Views versus in the CLI, or in Jobs (eg. links in emails). In the web context most of Laravel's URL generation is based on the server/request URL. For example, the url() helper calls methods in Illuminate\Routing\UrlGenerator that ultimately use Illuminate\Http\Request's URL methods.
The CLI and Queued Jobs don't have the Request object, so they have to fall back to something else. That's right, configuration.
So, even though links, redirects, and other generated URL's will function perfectly in the web, these can be "broken" (misconfigured ;) outside the HTTP request lifecycle if APP_URL isn't set in your .env, or directly in the app config as #Sachin Kumar points out.
I have an issue making my cakephp project work on my shared hosting server.
I followed all the needed steps so it can work on local, and it's working. Once I upload on the server, in a specific domain name, only the homepage works, once I want to call another controller, i get the "404 - File or directory not found." error.
the project is hosted at : fme.tahrijouti.com. the domain redirects to the webroot folder in the cakephp structure.
My controller is : posts. I can make it work if I change the URL by specifying the controller & action, you can see it here.
I have checked and the rewrite module is on.
Can you please help me with that ?
Please have a look on CakePHP default routing. And don't forget to fix all your links.
Your links should have proper addresses. Just look on your Posts's link. These are like this http://fme.tahrijouti.com/index.php/posts/posts/view/2 but it should be http://fme.tahrijouti.com/index.php/posts/view/2. Remember after your host name there exist controller then a function of that controller then argument of that function like this: [host]/[controller]/[function]/[argument1]/[argument2]. Hope it helps. I think you can read cookbook another bit as most things are clear there from my experience.
As I don't have your codes of controller I cannot say more.
UPDATE
If I browse url like
localhost/myapp/index.php/about_us/index
it works. What is this index.php in url? Do I need to mention it in some config file so that it gets appended and forms correct url in menu/links on site?
Original Question
I have no knowledge of PHP but I got a project which in php (codeigniter) to convert in Ruby on Rails.
I could set up db and application well, when I browse application with base url(without mentioning controller & action) it loads page properly. But as soon as I mention url like
localhost/myapp/home/index
it shows message
The requested URL was not found on this server.
If I change default controller to anything in routes.php that page with index method works fine but not with explicit mentioning controller and action.
I am not sure what is the issue, I don't know how routing works in php :(
Any help will be appreciated.
In CodeIgniter, all requests are directed through the index.php file, which acts like a front controller.
index.php must be present in the URL unless you have created a solution to eliminate it. When using Apache, that is typically done with an .htaccess file. There are hundreds of articles and questions regarding this technique -- certainly you can find something to help you.
In regards to URLs and a config option for defining index.php, CodeIgniter URL helper functions such as site_url() utilize the config setting $config['index_page'] found in application/config/config.php. If you remove index.php from your URLs using an .htaccess solution, you can make this setting blank:
$config['index_page'] = '';
This setting is useful for when you want to rename index.php to something else, as well (not very common).
It seems that you had not configured your web server properly. See this question for details for Apache: routing problem in codeigniter
And here are rules for nginx: http://wiki.nginx.org/Codeigniter