I need to redirect from a CGI to a page of the same server created in Laravel. When I use the path from a browser it presents itself without problems, but when using the CGI, Laravel presents an error to me.
https://myserver:8080/bitacora/index.php/devices
Error when using Location: /bitacora/index.php/devices header from a CGI
The only difference I see in PHP is that it does not use QUERY_STRING, but the "arguments" are delivered by the PHP_SELF variable.
Any ideas on how to act correctly? I remember that some frameworks redirect to a variable, such as module or action. Something similar in Laravel?
Use full URL
not just
Location: /bitacora/index.php/devices
But replace this with following
Location: http://myserver:8080/bitacora/index.php/devices.
Related
I have used Slim Framework several times without any problem but now I'm trying to set a route to match URL that ends with .html and render a certain view, but the framework return a 404 Not Found error, the route is ignored and it seems to me that just checks if there is a file named like that, and since there isn't, simply throw the 404.
The route I'm trying to set is this:
$app->get('/{slug}.html', BusinessController::class . ':business');
This is possible in Laravel and that's the reason I'm a bit confused. Maybe someone stumbled upon this issue and know a solution.
Firstly to achieve this you will need to disable your web server (apache, nginx or other) from serving static html pages for your project. Typically a url that ends with .html will cause web servers to check for the corresponding static html file.
Then you need to add rewrite logic in .htaccess file to make sure all *.html routes are passed to your frameworks route handler like index.php or server.php (I am not familiar with Slim). Then its a matter of how you have configured your framework to handle there routes.
$this->request->redirect('localhost/project2/');
From a controller in project1, I have this code, but it's always redirecting me to localhost/project1/index.php/localhost/project2. How can I properly redirect to localhost/project2/ ?
I tried using header() to redirect but its not working in Kohana. Im using Kohana 3.2 in PHP 5.5.12
You should use http before link to specify it is a complete URL:
$this->request->redirect('http://localhost/project2/');
And you shouldn't use the localhost as a static text in your code because your server will changed, you should use on of the ways to return your server root like $_SERVER['HTTP_HOST'] or if you use a MVC framework you can use its function that return base URL.
I started studying CodeIgniter Web Framework and I am trying to work with PHPStorm 8.0.3 on Kubuntu 14.04. When I unzip CodeIgniter downloaded archive to root Apache folder /var/www/html and go to
localhost/index.php
then it works okay and I see "Welcome to CodeIgniter!" page. Also I
can use
localhost/index.php/welcome/index
and see the same page as it should be.
When I created a new PHP project in PHPStorm and try
localhost:63342/codeignitor/index.php/
then I see welcome page, but if I use
localhost:63342/codeignitor/index.php/welcome/index
then I get 404 page. Also all my own controllers are not available and
cause 404.
I can call my own controller only if I make it default
$route['default_controller'] = 'mycontroller';
I think that this problem occurs because the URL contains name of my project /codeignitor/, but I'm not sure about it. So I need your advice how to set CodeIgniter environment in PHPStorm correctly to solve this problem. Thank you!
Codeigniter uses the URL to determine routing, therefore /codeigniter/index.php/welcome/index and /index.php/welcome/index are not equal paths. I would recommend using one or the other, and adjusting your /index.php and /config/routes.php to accommodate for your desired path.
References:
Codeigniter Subfolder
https://www.codeigniter.com/user_guide/general/urls.html
https://www.codeigniter.com/user_guide/general/routing.html
https://www.codeigniter.com/user_guide/general/environments.html
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
I finally got a basic framework set up and working, however now when I wish to add an action in the 'IndexController.php', it doesn't seem to be working.
I used the following terminal command to add an "about" action:
zf create action about index
It appears that worked, as I opened 'IndexController.php' back up and the new action function is there. And a corresponding 'about.phtml' file was created in 'views/scripts/index', alongside 'index.phtml' that was already there.
When I access the index at
http://localhost3:8888/
the page opens properly.
However if I now try to access the about page at
http://localhost3:8888/index/about
I get a "404 not found" error.
Any ideas?
Looks like a mod_rewrite problem.
Try http://localhost3:8888/index.php/index/about. If it works, then it definitely means that mod_rewrite wasn't correctly set up.