I have developed a web application using php (custom MVC). The web app works fine on the localhost but not on godaddy server.
I have written redirect function as following:
public function redirect($controllerName, $action, $params=null) {
if($controllerName){
$link = Constant::$APP_URL . "/" . $controllerName. "/" . $action; }else{ $link = Constant::$APP_URL . "/" . $action; }
if($params != null) {
$link .= "?" . http_build_query($params);
}
header("Location:" . $link);
exit;
}
Take the following example:
The following on local server works, when I try to login:
https://localhost/project/login
If I type the same on my server, it does not work & redirects me to the following link:
https://example.com/login/login
"login" is a function in one of the controllers.
Any ideas?
My .htaccess file looks like:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L,QSA]
hey could you please provide us with the error report from cpanel. if you go into your cpanel on godaddy then go to error log it should show a report at the specific time of action. like when the button pushed. if you have javascript as well and nothing shows up(which i doubt) also check google by right clicking and going inspect element. this will give more info for what is actually going on. from there we could source a solution or you might even be able to google possible solutions before you need to ask.
Related
After changing from HTTP to HTTPS in my OpenCart installation with Journal2 theme/plugin I have problem - admin panel for Journal2 not loads, showing "Loading..." state and that's all.
Journal2 version = 2.13
OpenCart version = 2.3.0.2
Current stack: PHP 7 + Apache2 + MySQL
Also adding screenshot.
What is broken? I have updated website url from http:// to https:// in admin panel, also updated variables in
config.php
and
/admin/config.php
files. Maybe problems with caching?
Kindly check the two config files for correct configuration of Data Base and file folders.
Also u need to check the file in system/library/url.php
on that,
public function link($route, $args = '', $secure = false) {
if ($this->ssl && $secure) {
$url = 'https://' . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/.\\') . '/index.php?route=' . $route;
} else {
$url = 'http://' . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/.\\') . '/index.php?route=' . $route;
}
if ($args) {
if (is_array($args)) {
$url .= '&' . http_build_query($args);
} else {
$url .= str_replace('&', '&', '&' . ltrim($args, '&'));
}
}
foreach ($this->rewrite as $rewrite) {
$url = $rewrite->rewrite($url);
}
return $url;
}
Hope It will helps you.
Did you properly configure your site for SSL use? Let's go over some things here:
Not to sound repetitive, but are you very sure that both your config files are correct? Not sure what you meant before when you said you took "the path for the root" from some page when it's pretty much the url that anyone's going to go visit your site/store. I'm assuming your store/opencart is in it's own folder and not in the root directory, yes? If so:
admin/config.php file should have something like this:
// HTTP
define('HTTP_SERVER', 'http://www.yourwebsite.com/opencart/admin/');
define('HTTP_CATALOG', 'http://www.yourwebsite.com/opencart/');
// HTTPS
define('HTTPS_SERVER', 'https://www.yourwebsite.com/opencart/admin/');
define('HTTPS_CATALOG', 'https://www.yourwebsite.com/opencart/');
config.php file should have something like this:
// HTTP
define('HTTP_SERVER', 'http://www.yourwebsite.com/opencart/');
// HTTPS
define('HTTPS_SERVER', 'https://www.yourwebsite.com/opencart/');
and by what I recall from past experience that forward slash matters at the end.
Also, it matters very much if your url is: yourwebsite.com vs www.yourwebsite.com just to point out that, too.
Speaking of which... how about your .htaccess file? That could be a culprit here, too. I'm referring to the htaccess file for your root directory and not opencart's htaccess. That may need to be altered correctly to for https. As an example:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourwebsite.com/$1 [R,L]
RewriteCond %{HTTP_HOST} ^(www.)?yourwebsite.com$
RewriteCond %{REQUEST_URI} !^/opencart/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /opencart/$1
RewriteCond %{HTTP_HOST} ^(www.)?yourwebsite.com$
RewriteRule ^(/)?$ opencart/index.php [L]
If you notice here, you need to include the server port and https. So maybe check that, too.
Our site allows for a pretty url 'etest.me/1234' where '1234' is a client id. As you can see below it redirects to our route.php file where we do our redirect. The problem is when a client uses 'etest.me' without the '/1234' they get the apache 'The requested URL /go/ was not found on this server.' message. I would like the url to go to another page when the '/1234' is missing.
Note that we have the domain and path forwarded to the non-existing '/go' directory so the rules below will catch it. The following is in our .htaccess file in the root directory.
RewriteEngine On
#restrict rewriting URLs ONLY to paths that DO NOT exist
RewriteCond %{SCRIPT_FILENAME} !-d
# commented out to speed up looking since we are not processig file names anyway
#RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^go/([a-zA-Z0-9/]+)$ ./route\.php?go=$1
Working perfectly fine for me. Hope this will work for you as well.
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^go/([a-zA-Z0-9]+)$ /route.php?go=$1 //when client id exist
RewriteRule ^([a-zA-Z0-9]+)$ /index.php // when no client id
You can add a new rule to handle this situation:
RewriteRule ^go/$ ./another_script\.php
I accepted the answer by Sahil and posted the entire logic below for others to use:
Domain: etest.me
Pretty URL: etest.me/1234 (where '1234' is a client id)
Forwarded to: etesting.io/go (with forward path option selected so the '/1234' will be include in the forward)
Note: There is no '/go' directory on the server, '/go' is used to trigger the redirect.
Wanted 'etest.me' (without client id) to go to index file in root directory.
Here is the rewrite rules in .htaccess:
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^go/([a-zA-Z0-9/]*)$ ./route\.php?go=$1
Here is the route.php code:
<?php
if($_GET['go']){
$a = explode('/', $_GET['go']);
$c = count($a);
if($c == 1 || $c == 2){
header('location: ../../index.php?aid=' . $a[0] . '&tid=' . $a[1]);
exit;
}
else{
die('Invalid URL');
}
}
else{
header('location: ../index.php');
exit;
}
And finally the index.php file:
if($_GET['aid'] && $_GET['tid']){
header('location: test/register.php?aid=' . $_GET['aid'] . '&tid=' . $_GET['tid']);
exit;
}
elseif($_GET['aid']){
header('location: test/index.php?aid=' . $_GET['aid']);
exit;
}
else{
header('location: account/index.php?' . $_SERVER['QUERY_STRING']);
exit;
}
Hope this helps somebody in the future.
I would like a more elegant solution but it's behind me for now...
Hi this is my first time asking a question on here so go a little easy on me if my question is not clear or my code is not right lol. I currently uploaded my new php mvc website to 123-reg.co.uk and im using apache mod_rewrite with a router class. It works perfectly when im on my localhost but when its live, the mod_rewrite is ignored and the controller is not recognised e.g if i type http://www.examplewebsite.co.uk the home controller loads like it should but if i try to load a different controller e.g http://www.examplewebsite.co.uk/images it takes me too a server error 404 page. I have been trying to fix this for several days now with no success, i have done some research and 123-reg.co.uk does support mod_rewrite, i feel like im loosing it haha, any help would be greatly appreciated, Thanks in advance.
This is the router class:
class Router {
public function __construct()
{
if(empty($_GET['url']))
{
Help::loadApplication('controllers','home');
return new Home();
}
elseif(isset($_GET['url']))
{
$url = $_GET['url'];
$url = rtrim($url,'/');
$url = filter_var($url,FILTER_SANITIZE_URL,true);
$url = explode('/',$url);
Help::loadApplication('controllers',$url[0]);
if(class_exists($url[0]))
{
$controller = new $url[0];
if(isset($url[1]))
{
$methodName = $url[1];
if(method_exists($controller, $methodName))
{
$methodParams = (isset($url[2]) ? $url[2] : false);
$controller->{$methodName}($methodParams);
}
}
}
else
{
Help::loadApplication('controllers','home');
return new Home();
}
}
}
This is the mod_rewrite:
RewriteEngine On
RewriteBase /http://www.examplewebsite.co.uk
Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php/?url=$1 [QSA,L]
UPDATE !!
Anyone else that has this same issue, the reason it wasn't working is because 123-reg.co.uk don't support mod_rewrite on their Windows package but do on there Linux package, it would have been good for them to state that when I signed up for the Windows package but making the switch over to the Linux package now. Thanks for the help guys!
This is worth trying; Add this as your first line above RewriteEngine On
Options +FollowSymlinks
source: http://forum.modrewrite.com/viewtopic.php?f=4&t=2222
and I'm not so sure about your RewriteBase, maybe it should be
RewriteBase /
instead of having the full url?
I have this htaccess filecontent:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^admin/([a-zA-Z]+)/?([a-zA-Z0-9/]*)$ public/admin/index.php?page=$1&query=$2 [L]
RewriteRule ^([a-zA-Z]+)/?([a-zA-Z0-9/]*)$ public/index.php?page=$1&query=$2 [L]
And now im trying to make a redirection depending on a session, very simple stuff. I have a Controller with this function:
protected function redirect($url) {
header("Location: http://localhost:8888/myproject/" . $url, true);
exit();
}
The ClientController that extends Controller has the page function
private function user_page() {
$this->redirect("homepage"); //Not working...
}
I have tried different ways of writing the location path like
Location: localhost:8888/myproject/" . $url,
Location: /myproject/" . $url,
Now after reading all posts on stackoverflow, I see none of these solutions have worked for me..
Edit: the solution to this can be seen on header redirect to Location does not work
After getting an answer from header redirect to Location does not work I found that the problem was some row of spaces that had been inputted after ?> in the Controller, so it took a while to notice it.
Clarification:
If you have the same problem make sure you have line numbers set and see if you can see any line numbers after the file content. If there is you may have blank lines after aswell. Just delete these. Needless to say, the same goes for linenumbers before filecontent
Kind of a weird one here: I have a Zend Framework setup in 1.12. My models are working fine and all of my includes are set...but in the view Zend can't seem to find a FusionCharts.js file that is there. I have it appended in the action as follows and when I check the path on Firebug it is absolutely correct- but still returns an error and claims that it can't find the .js file. Anyways- here's the code:
public function indexAction()
{
try{
$model = new Application_Model_DbTable_Daily;
$dau = $model->getStats();
$this->view->dau = $dau;
}
catch(Exception $e) {
$this->view->dau = $e;
}
$this->view->headScript()->appendFile('/dashboard/public/fusioncharts/Charts/FusionCharts.js');
}
So- in my view I get:
<?php
echo $this->headScript();
echo "<pre>";
$FC = new FusionCharts("Line", "500", "300");
$FC->setSwfPath("/public/fusioncharts/Charts/");
$strParamDAU = "caption=Daily Active Users;streamlinedData=0;decimals=0;decimalPrecision=0;formatNumberScale=0;slantLabels=1;labelDisplay=ROTATE";
$FC->setChartParams($strParamDAU);
foreach($this->dau as $k=>$v) {
$FC->addChartData($v['session_date'], "label=" . $v['DAU']);
}
$FC->renderChart();
echo "";
But when I look at the view in firebug I get an error saying that it can't find FusionCharts.js in the public directory (the path is definitely right!). Any ideas why this would be happening? It's there. The Firebug reads the right directory (GET localhost/dashboard/public/fusioncharts/Charts/FusionCharts.js) but the firebug error is saying that it can't see the file. Thanks for the help!!
If the file is realy there, and the Name is FusionCharts.js:
Try to add the BaseUrl (just to be on the safe side):
$this->view
->headScript()
->appendFile($this->view->baseUrl() . '/dashboard/public/fusioncharts/Charts/FusionCharts.js');
Next check your .htaccess, maybe you arent forwarding JS Files? Correct .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]