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?
Related
I am trying to write a PWA ready MVC framework in PHP. Controllers and Models are written in PHP, and the views are plain HTML assisted by AJAX.
So I started by building a URL routing class to manage requests. I also wrote a Session class, and it is working fine.
But my problem here is, I need some static HTML pages at the client side, for caching purposes. But I don’t want these files to be accessed without login. Let’s say I have a folder structure such as:
/ LIBS
/ route.php
/ Static
/ index.html
index.php
When I enter a URL like: mysite.com/foo/bar, routing class does the job and returns an array:
array (
0 => 'foo',
1 => 'bar',
)
That is good. But when I enter mysite.com/static it just goes into STATIC folder and brings index.html which is located inside that folder.
I want these files be accessed via php with Session control, after successful login. But I don’t want my visitors to access these files before logging in.
I tried to disable the access with htaccess, but this time I could not access them via PHP either.
Here is my index php:
<?php
include "/LIBS/route.php";
$route = new Route;
$route->init();
Here is my Router
<?php
class Route {
// Prints the URL array
public function init()
{
echo '<pre>' . var_export($this->_getUrl(), true) . '</pre>';
}
// gets the current URL and returns an array
private function _getUrl()
{
$url = isset($_GET['url']) ? $_GET['url'] : null;
$url = rtrim($url, '/');
$url = filter_var($url, FILTER_SANITIZE_URL);
$url = explode('/', $url);
return $url;
}
}
And here is my htaccess file
php_flag display_errors on
php_value error_reporting 9999
RewriteEngine On
RewriteBase /mvc/
# DirectoryIndex none.none
# Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
There is a kind of relevant SO question here which doesn't seem to be the answer to my question.
I digged everywhere but could not find an answer. What am I missing?
Thanks
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.
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.
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]