thedigicraft / Atom.CMS

Atom.CMS
56 stars 52 forks source link

Clean URLs #98

Closed maaka closed 9 years ago

maaka commented 9 years ago

I'm having an issue with the clean URLS section. It doesn't seem to work for me, and that part of the site is broke at this point. I was looking over the code, and can't to figure out where the issue is. I uploaded the sql db, and .htaccess files from repo. I noticed from where I'm at now the files will be changed so maybe the issue will work its way out. But I would still like to troubleshoot this issue. Any tips on where to start?

creptor commented 9 years ago

problems related to the clean urls sitem could only be geretated by tree files in this proyect. The setup.php(or main config file), the sandbox.php, and the .htaccess file. Please check that those files match the ones in this repository.

--Notes: some host providers already have a default .htaccess wich by they terms could or could'nt be modified, altered, or be revocated. If that's not your case (read carefully the help seccion of your server about clean url's) add this 'RewriteBase /' on top of everything of your .htaccess file.

maaka commented 9 years ago

Creptor, Thanks for your help. I compared my .htaccess and sandbox.php files to what was in repo. Everything matched up, but I took it a step further and pasted that code into those files. The setup.php file in repo was a newer version then what I have now, but not that far off. I also ensured my db connection didn't changed somehow. Still doesnt work. I'll paste my setup.php code here. Also I'm doing this all locally on my laptop running wamp.
Thanks again <?php //Setup File error_reporting(0);

// DB Connection include 'connection.php';

Constants

DEFINE('D_TEMPLATE', 'template');

Functions

include 'functions/sandbox.php'; include 'functions/data.php'; include 'functions/template.php';

Site Setup

$debug = data_setting_value($dbc, 'debug-status');

$path = get_path();

$site_title = 'Atom 2.0';

// Check that page exists, page is stated from browser if(!isset($path['call_parts'][0]) || $path['call_parts'][0] == '') {

//$path['call_parts'][0] = 'home'; // Set $page_id to equal the value given in the URL
header('Location: home');

}

Page Setup

$page = data_page($dbc, $path['call_parts'][0]);

creptor commented 9 years ago

that's some funny looking code. use ``` in the front of your file and in the end to make it look like code easily. for more info see Fenced code blocks. Now.....

checks:

function get_path(){
  $path = array();
  if(isset($_SERVER['REQUEST_URI'])){
    $request_path = explode('?', $_SERVER['REQUEST_URI']);
    $path['base'] = rtrim(dirname($_SERVER['SCRIPT_NAME']), '\/');
    $path['call_utf8'] = substr(urldecode($request_path[0]), strlen($path['base']) + 1);
    $path['call'] = utf8_decode($path['call_utf8']);
    if($path['call'] == basename($_SERVER['PHP_SELF'])){
      $path['call'] = '';
    }
    $path['call_parts'] = explode('/', $path['call']);
    $path['query_utf8'] = urldecode($request_path[1]);
    $path['query'] = utf8_decode(urldecode($request_path[1]));
    $vars = explode('&', $path['query']);
    foreach($vars as $var){
      $t = explode('=', $var);
      $path['query_vars'][$t[0]] = $t[1];
    }
  }
return $path;
}
RewriteBase /
AddDefaultCharset UTF-8
<IfModule mod_rewrite.c>
    RewriteEngine On
    Options -Indexes
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>
maaka commented 9 years ago

creptor thanks for your help. I confirmed that my .htacess is just a file no extension. I copied the code for sandbox and .htaccess you posted in their respective pages. My setup.php code at the bottom shows $page = data_page($dbc, $path['call_parts'][0]); So now I get a 500 not sure if this is progress or not :/ If there any code you would like me to post to help resolve this?

creptor commented 9 years ago

it's really hard to get an 500 error, my gess is that the xamp didn't install successfully. (servers error is for 500) Try reinstalling xamp, without the antivirus or any other program running, and from the main page here. if it doesn't work please let me know. I also recomend you install everything for the xamp installation.

maaka commented 9 years ago

Not sure how much difference it makes, but I'm using WAMP. Honestly this is the first time I've had any issues. Of course this is the first time I've tried clean URLS. For troubleshooting purposes I'm willing to install XAMP, unless there is some sort of odd variance between the two.

creptor commented 9 years ago

well wamp and xamp are almost the same thing they just have diferent versions of php, apache, or other functions that they might give but they are almos the same, though i'll recomend xamp as primary tool because it's easy to install and be used (more updates and you don't need to know your operating sistem). if you do not wish to install xamp please ensure you have the righ version of wamp for your computer. apache might be trowhing those 500 errors because of the operating sistem bits.

maaka commented 9 years ago

Ok I'll give it a shot.

thedigicraft commented 9 years ago

@maaka make sure to check and see if your permissions are correct. I have had issues with that on remote linux servers. However, cannot say that I have had it on my local Windows server running xampp. It's worth a look though!

creptor commented 9 years ago

if you still have any problems please in your next post place the errors or anything you get when trying to open your site, please.(if you know how to get the log it would be much better)

maaka commented 9 years ago

Ok will do. I should have some time tonight to try xamp. I know how to get logs of a linux server, but I'm sure a quick google search will show me how to get logs off wamp. In the mean time I'll post my code that I have. Maybe I missed something.

setup.php

<?php
//Setup File
error_reporting(0);

// DB Connection
include 'connection.php';

#Constants
DEFINE('D_TEMPLATE', 'template');

# Functions
include 'functions/sandbox.php';
include 'functions/data.php';
include 'functions/template.php';

#Site Setup
$debug = data_setting_value($dbc, 'debug-status');

$path = get_path();

$site_title = 'Atom 2.0';

// Check that page exists, page is stated from browser
if(!isset($path['call_parts'][0]) || $path['call_parts'][0] == '') {

    //$path['call_parts'][0] = 'home'; // Set $page_id to equal the value given in the URL
    header('Location: home');
}

#Page Setup
$page = data_post($dbc, $path['call_parts'][0]);

sandbox.php

<?php

function get_path(){
  $path = array();
  if(isset($_SERVER['REQUEST_URI'])){
    $request_path = explode('?', $_SERVER['REQUEST_URI']);
    $path['base'] = rtrim(dirname($_SERVER['SCRIPT_NAME']), '\/');
    $path['call_utf8'] = substr(urldecode($request_path[0]), strlen($path['base']) + 1);
    $path['call'] = utf8_decode($path['call_utf8']);
    if($path['call'] == basename($_SERVER['PHP_SELF'])){
      $path['call'] = '';
    }
    $path['call_parts'] = explode('/', $path['call']);
    $path['query_utf8'] = urldecode($request_path[1]);
    $path['query'] = utf8_decode(urldecode($request_path[1]));
    $vars = explode('&', $path['query']);
    foreach($vars as $var){
      $t = explode('=', $var);
      $path['query_vars'][$t[0]] = $t[1];
    }
  }
return $path;
}

function selected ($value1, $value2, $return){

    if($value1 == $value2){

        echo $return;
    }
}

.htaccess

RewriteBase /
AddDefaultCharset UTF-8
<IfModule mod_rewrite.c>
    RewriteEngine On
    Options -Indexes
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>
maaka commented 9 years ago

So I think at least found what caused my 500 issues, I removed

RewriteBase /
AddDefaultCharset UTF-8

And now just the 404 error I had before. The path in my browser is http://localhost/atomcms/home. So I believe thats at least correct. So at this point I'm not 100% sure its a wamp/xampp issue. But I'm going to give it a shot regardless.

creptor commented 9 years ago

well that would be my fault :cry: I give you that code because in xamp the apache was configured to have that RewriteBase with no errors. sry but that thing your having is interesting, it's obviously an apache related issue with the predefined values.(that's why the rule didn't work) It appears that in wamp you have to edit the apache config to be able to use the rules.(like the <IfModule mod_rewrite.c>) I recomend you google changing config for apache, <IfModule mod_rewrite.c> or <IfModule mod_rewrite.c> wamp. if you have the logs that tells you that an error ocured google the error :ghost:.

maaka commented 9 years ago

Ok not sure how helpful this thread is for the good of the world at this point. If the code I recently posted is correct up to the point of clean URLs, then I'm looking at an Apache issue. So this may take some googling to figure out the fix. Just from a google search I'm seeing different methods of implementing Clean URLs with Apache then what the videos show. On my local server I'm running Apache 2.4.9 in WAMP. I also enabled the rewrite module.

creptor commented 9 years ago

you installed wamp? did it work? do you have the same problem?

creptor commented 9 years ago

I have found something... hope it helps you out :smile: link

NOTE: for me (xamp) it was enabled by default. You have to restart the server. PD: the AllowOverride must be by himself not with <Directory "C:/xampp/cgi-bin"> AllowOverride All.....

maaka commented 9 years ago

Creptor, did you mean XAMPP? I did install XAMPP but haven't a chance to get further then that. Ill have a chance to try it out tonight. I posted the sandbox etc... code above, did you get a chance to look at that? Just wanted to confirm its at least correct up to the video about configuring clean urls. The .htaccess file is of course wrong since its for XAMPP. Also thanks for the link, I will try that out as well tonight.

creptor commented 9 years ago

The code is right. yea xamp is xampp for me, i'm just too lazy to type an extra p :ghost:. the link that i posted before should fix your problem with wampp so you can continue to use your favorite web server emulator :smile: .

maaka commented 9 years ago

Ok i think we are making some progress here. I get this message now The requested URL /index.php was not found on this server. The URL i have in my browser is http://localhost/atomcms/home

creptor commented 9 years ago

yea there could be now two errors but the clean url problem was fixed. Please I ask you to start another issue to keep things clean and related to it's topics, so please create a new issue. Thanks

Chriswilldo commented 9 years ago

I haven't read this in depth yet but this issue happened to me as well I believe. I finished the series but ever since the clean url's, the site broke. I could still use the user dashboard fine and all but front end would only show the Home page.

creptor commented 9 years ago

@Chriswilldo make an issue so I can help you. I like to start fresh :smile:.