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.
Related
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...
I'm having a few problems getting a PHP script to work on a new server - I've gone from apache to a Litespeed server, and I can't get the little CMS to work on it.
In a nutshell the .htaccess contains:
ServerName www.domain.co.uk
ServerAlias domain.co.uk
DocumentRoot /home/domain/public_html/
<Directory /home/ttedomainpublic_html/>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.co.uk [NC]
RewriteRule ^(.*)$ index.php [L]
RewriteRule ^(.*) http://www.domain.co.uk/$1 [L,R=301]
RewriteBase /
RewriteRule ^(admin|content|css|images|img|non_public|pdf|renderers|scripts|sendmail|templates) - [L]
</Directory>
And the index.php contains:
<?php
include("non_public/config.php");
// Get the request URI
$requestUri = $_SERVER['REQUEST_URI'];
$requestUri = preg_replace("~^/~","",$requestUri);
$requestUri = str_replace("/","_",$requestUri);
// Make sure that we'll get the index
if(empty($requestUri)) $requestUri = "index";
if(file_exists(ROOT_PATH . "content/" . $requestUri))
{
// Include the header
include(ROOT_PATH . "templates/header.php");
// Check if there's a renderer
if(file_exists(ROOT_PATH . "renderers/" . $requestUri . ".php"))
{
include(ROOT_PATH . "renderers/" . $requestUri . ".php");
}
else
echo file_get_contents(ROOT_PATH . "content/" . $requestUri);
// Include the footer
include(ROOT_PATH . "templates/footer.php");
}
else
echo file_get_contents(ROOT_PATH . "content/404");
?>
So the above should throw a page together from the content file held in content/, a few bits and bobs from the template and some basic things from the renderers/ directory.
I hope that makes sense so far? This has worked well on an Apache server for a few years, but just doesn't work under Litespeed.
The current end result when you go to www.domain.co.uk/notes is simply a 404 page, because obviously www.domain.co.uk/notes/index.php etc. doesn't exist and the server can't seem to put the page together.
Can anyone please point me in the right direction?
Many thanks...
Try enabling rewrite logging and visiting the page. The rewrite log should explain what's happening within the rewrite rules.
I have a project running local on WampServer. It's an MVC-like structure; it rewrites the URL to index.php?url=$1. Full .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
When I want to send the user to another page using PHP location: <location> it doesn't do this properly because of the rewriting (all-though I am technically always in index.php).
For example if I am on http://localhost/project_name/controller/method/ and this controller's constructor or method tries to send me to:
header('location: another_controller/method'); sends me to
http://localhost/project_name/controller/method/another_controller/method/
header('location: /another_controller/method'); sends me to
http://localhost/another_controller/method/
But I want it to send me like this:
header('location: /another_controller/method'); sends me to
http://localhost/project_name/another_controller/method/
Now the only solution I have found is:
define('BASE_URL','http://localhost/project_name');
header('location: '.BASE_URL.'/another_controller/method/');
But this isn't perfect either because it causes me to have to change this defined constant BASE_URL whenever the domain or folder name changes. I could also create a method in my BaseController that creates absolute URLs, but this method would basically just prepend BASE_URL too.
Note: The same problem doesn't arise with HTML's src and href attributes, which can use relative paths (without project_name folder in path). I don't understand why however. Because if the header location causes the browser to append the the relative-URL to the current location, why doesn't it have the same behavior when looking for .css or .js files.
So... this raises a couple of questions for me:
Would I have this problem if I had virtual hosts?
What is the best way to solve this problem?
Is is best to just have the full absolute URL?
Why do HTML's src and href attributes not share this behavior?
Now the only solution I have found is:
define('BASE_URL','http://localhost/project_name');
header('location: '.BASE_URL.'/another_controller/method/');
But this isn't perfect either because it causes me to have to change
this defined constant BASE_URL whenever the domain or folder name
changes.
You shouldn't need to change the defined constant. These values can be found dynamically.
Example:
if ($_SERVER['DOCUMENT_ROOT'] == dirname($_SERVER['SCRIPT_FILENAME'])) {
define('BASE_PATH', '/');
} else {
define('BASE_PATH', dirname($_SERVER['SCRIPT_NAME']) . '/');
}
$protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
define('BASE_URL', $protocol . $_SERVER['SERVER_NAME'] . BASE_PATH);
Additionally, rather than worrying about whether to specify an absolute URL or a path, you can wrap the redirect into a function which can handle both:
function redirect($path = null) {
if (isset($path)) {
if (filter_var($path, FILTER_VALIDATE_URL)) {
header('Location: ' . $path);
} else {
header('Location: ' . BASE_URL . $path);
}
} else {
header('Location: ' . BASE_URL);
}
exit;
}
Finally, as #HarshSanghani mentioned in the comments, the base path in your .htaccess file should match the base path in your code. So if BASE_PATH (based on the example above) outputs /project_name/, then your .htaccess should accommodate it:
RewriteBase /project_name/
To answer your questions:
It depends on how your virtual hosts would be configured.
You could simply generate your BASE_URL dynamically: $baseUrl = dirname($_SERVER['SCRIPT_NAME']);. This way you won't have to change any code if your folder or domain changes.
You don't need the domain part.
The html src and href are interpreted by your browser which takes into account the page's <base> tag. All paths on a page with a <base> tag get changed accordingly by your browser.
The HTTP headers you send from your server (for redirect) have nothing to do with the html page you send and are therefore not updated.
You're going to have this problem if you have your project set up in a subdirectory. Using virtual hosts would be a way round the issue if you wanted to set them up at say, project_name.localhost.
In my projects I use an environment variable to load a different config file for development, staging or production. In this I set a $baseUri somehow.
It's best practice to use the absolute urls (including the domain) for both the solution of this problem and for SEO. In terms of functionality you don't need the domain part.
The src and href tags generally work the same way, but as Andreas mentioned they could be affected by the base tag.
You should specify RewriteBase in your htaccess file. Use relative paths in your links and you need nothing more.
RewriteBase /project_name/
RewriteEngine on
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
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've tried to find an answer for a question i had in my mind, but it seems to I can't find it.
How is it possible to make some php urls with "?" and "=" to /
Example one (1):
example.com/user.php?profile=example
to:
example.com/user/profile/example
Example two (2):
example.com/forum.php?thread=example-in-an-example
to:
example.com/forum/thread/example-in-an-example
Like a code that takes the second "/" (slash) as a "?" and the third and the rest as a "=" so i can freely use it instead of making a new one for each page...
LIKE: /forum (or any others) is like the page itself
AND: /thread (or any others) is like the $_GET
AND: /example-in-an-example (or any others) is like the value to the $_GET
EXTRA:
here is a code from Jeroen:
RewriteRule ^(.*)/(.*)/(.*)/$ $1.php?$2=$3 [L]
Problem one (1): when going to like: "example.com/forum" or "example.com/user" its giving a 404 error
Problem two (2): When using links like "example.com/forum/thread/test-thread/reply/2" it gives 404 error, (supose to loop with "&" and "=" after making the 1st real one so its enable to use more than one $_GET)
Add this to your .htaccess file:
RewriteEngine On
RewriteRule ^user/profile/(.*)/$ user.php?profile=$1 [L]
RewriteRule ^forum/thread/(.*)/$ /forum.php?thread=$1 [L]
Or a more generic version...
RewriteEngine On
RewriteRule ^(.*)/(.*)/(.*)/$ $1.php?$2=$3 [L]
Make sure Apache's mod rewrite is enabled!
If you have full access to the application and you can modify the code, I can submit you some trick I usually use for my REST utilities.
Put AllowOverride All inside your apache configuration to enable .htaccess file.
Assure to LoadModule your mod_rewrite module too.
Create a .htaccess file into your web server document root (your application path) and put this stuff inside:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
Create a file called index.php and put this inside, this will be your controller:
<?
// echo "REQUEST_URI: " . $_SERVER['REQUEST_URI'] . "</br>\n";
$controller = explode("/", $_SERVER['REQUEST_URI']);
//print_r($controller);
$resource = $controller[1];
$operation = $controller[2];
$operation_value = $controller[3];
echo "Requested resource: $resource, opetation: $operation, value: $operation_value<br>\n";
switch($resource) {
case 'user':
echo "User requested\n";
//require_once("user.php");
break;
case 'forum':
echo "Forum requested\n";
//require_once("forum.php");
break;
/* add any other resource */
default:
echo "Requested page was not found.\n";
break;
}
?>
When the user call http://example.com/user/profile/ZeroXitreo the page will be renderer as:
Requested resource: user, opetation: profile, value: ZeroXitreo
User requested
When the user call http://example.com/forum/thread/example-in-an-example the page will be:
Requested resource: forum, opetation: thread, value: example-in-an-example
Forum requested
Read the PHP code of the controller, I think it's quite self explaining.