Here are the rules I am using for the Url Manager.
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing' => false,
'rules' => [
'post/<arg1>/<arg2>/<arg3>/<arg4>' => 'post/filter',
'posts' => 'post/index',
],
],
And my .htaccess
RewriteEngine on
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php
The rule seems to be working and urls like
post/filter?arg1=9&arg2=0&arg3=d&arg4=3 is getting turned into,
post/9/0/d/3
However, I have a search form like below
$form = ActiveForm::begin([
'action' => Url::to(['post/filter']),
'method' => 'get'
the fields in the form are named arg1,arg2,arg3,arg4. Now whenevr I submit the form the url gets back to the format
post/filter?arg1=9&arg2=0&arg3=d&arg4=3
I am not sure if its got something to do with the rules or the way I am submitting the form (I need submit the form by GET method only). Any help? Thanks.
Try this rule
'post/filter?<arg1:\w+>=<val1:\d+>&<arg2:\w+>=<val2:\d+><arg3:\w+>=<val3:\d+><arg4:\w+>=<val4:\d+>' => 'post/filter/<val1>/<val2>/<val3>/<val4>'
Related
Hi i am new to codeignitor my application works fine in my local host but when i bring it live server it gives me the below error
Error after login
My config file i have already set the base_url to
$config['base_url'] = 'http://diamondglass.com.sg//portal/';
and
$config['index_page'] = '';
My .htaccess is in my portal folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
My index function in my project Controller
function index()
{
$data['projects'] = $this->project_model->getAll();
$data['users'] = $this->user_model->getAll();
// set array of items in session for page
$arraydata = array(
'mainsection' => 'Projects',
'subsection' => 'Projects'
);
$data['statuscount'] = $this->project_model->getStatusCount();
$this->session->set_userdata($arraydata);
$this->load->view('admin/project/index',$data);
//echo '<pre>';
//print_r($this->session->userdata());
}
My Login Controller
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login extends CI_Controller {
function __construct()
{
parent::__construct();
if($this->session->userdata('user'))
redirect('admin/project');
$this->load->helper(array('form'));
$this->load->library(array('form_validation'));
}
public function index()
{
$this->load->view('login');
}
//To Verify Logins
function verify()
{
$this->load->model('user_model');
/* Load form validation library */
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
if($this->form_validation->run() == TRUE)
{
//model function
$this->load->model('user_model');
$check = $this->user_model->validate();
if($check)
{
$this->session->set_userdata('user','1');
$this->session->set_userdata('currentUser',$check);
redirect('admin/project');
}
else
{
$this->session->set_flashdata('error', 'Invalid Username and Password');
redirect('login');
}
}
else
{
//false
redirect('login');
}
}
}
I have been searching the web high and low for a solution, but i can figure this out. I know it got to do with .htaccess but can't figure this out. can someone help
IMHO, your base_url has wrong (// after .sg)
Second, make sure your view-file is located at: ../Views/admin/project/index.php
You don't have to put the IfModule tags every time. Use this code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
ErrorDocument 404 http://diamondglass.com.sg/404.html
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/404/$
RewriteRule ^(.*)$ <YourRelativePathToPHPFile>/404.html [L]
Make sure you have a custom 404 page
here's the challenge: i need to make the imitation of subdomains. Actually all the "subdomains" in the project are simple actions of the main SiteController like
example.com/index.php/site/subsite?id=subname
example.com/index.php/site/about?id=subname
example.com/index.php/site/contacts?id=subname
etc. I need them to look like
subname.example.com/
subname.example.com/about
subname.example.com/contacts
etc. I have included urlManager rules like this:
'rules' => [
'http://<id:\w+>.site.com/about' => 'site/about',
'http://<id:\w+>.site.com/contacts' => 'site/contacts',
'http://<id:\w+>.site.com' => 'site/subsite',
],
And made a .htaccess file that is :
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^([a-zA-Z0-9]*).site.com [NC]
RewriteRule %{HTTP_HOST} "^([a-zA-Z0-9]*)$.site.com" "site.com/index.php/subsite?id=$1" [L]
But it (predictably) doesnt work as i am not strong in rewrite rules. What am i doing wrong ?
I would do it like this:
Configure one virtual host on web server to host all subdomain and point to the Yii2 application
Write component Subdomain.php and put it in frontend\components
<?php
namespace frontend\components;
use Yii;
use yii\base\Component;
class Subdomain extends Component {
private $_subdomain = false;
public function init() {
parent::init();
list($this->_subdomain) = explode('.', $_SERVER['HTTP_HOST']);
}
public function __toString() {
return $this->_subdomain;
}
}
?>
In frontend\config\main.php in the 'components' section add:
'subdomain' => [
'class' => 'frontend\components\Subdomain'
],
Then in the project where I need subdomain I would use:
$subdomain = \Yii::$app->subdomain;
I need advise for htaccess rule to decode url string for instance:
Actual Page is
http://www.mycarhelpline.com/index.php?option=com_latestnews&view=detail&n_id=953&Itemid=10
But Page is cached in Google as
http://www.mycarhelpline.com/index.php%3Foption%3Dcom_latestnews%26view%3Ddetail%26n_id%3D953%26Itemid%3D10
Decoded string will lead to correct url
I am sorry as is not at all aware of htaccess rule, hence not pasting code. Is there any htaccess rule to remove escaped characters and lead to correct url through redirect
Update
Like as given in
https://docs.joomla.org/J2.5:Developing_a_MVC_Component/Basic_backend
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import joomla controller library
jimport('joomla.application.component.controller');
// Get an instance of the controller prefixed by HelloWorld
$controller = JController::getInstance('HelloWorld');
// Get the task
$jinput = JFactory::getApplication()->input;
$task = $jinput->get('task', "", 'STR' );
// Perform the Request task
$controller->execute($task);
// Redirect if set by the controller
$controller->redirect();
Shall i add this line in get the task - will it do the needful
$url = urldecode($jinput->get('url', '', 'string'));
Final Code is
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
require_once( JPATH_COMPONENT.DS.'pager.cls.php' );
// import joomla controller library
jimport('joomla.application.component.controller');
// Get an instance of the controller prefixed by HelloWorld
$controller = JController::getInstance('HelloWorld');
// Get the task
$jinput = JFactory::getApplication()->input;
$task = urldecode($jinput->get('task', "", 'STR' ));
// Perform the Request task
$controller->execute($task);
// Redirect if set by the controller
$controller->redirect();
?>
HTACCESS COde - Though working Good Partially but is notconverting %3f to ?
RewriteCond %{QUERY_STRING} ^(.*)\?(.*)$
RewriteRule ^(.*)$ /$1?%1\%3F%2 [L]
RewriteCond %{QUERY_STRING} !^$
RewriteRule ^(.*)$ /$1\%3F%{QUERY_STRING}? [L,NE]
Update - Final HTACCESS
RewriteCond %{QUERY_STRING} !^$
RewriteRule ^(.*)$ /$1?%{QUERY_STRING} [L,NE]
I have created a working magento site now I am trying to create a test environment based on the existing working site. It is on the same server and will be under a different sub domain.
workingSubDomain.domain.com/store/
newSubDomain.domain.com/store/
I have kept the substore directory structure the same as the working site.
I have gone through and set all of the folders to 755 with the app/etc/, media, var set to 777
After I click continue on the installation wizard configuration page I recieve a 500 error.
The server log file shows the following:
PHP Fatal error: Call to a member function insert() on a non-object in /var/www/vhosts/domain.com/magentoFolder/subStore/app/code/core/Mage/Core/Model/Resource/Resource.php on line 133, referer: http://newSubDomain.domain.com/subStore/index.php/install/wizard/config/?config%5Blocale%5D=en_US&config%5Btimezone%5D=America%2FChicago&config%5Bcurrency%5D=USD
I have tried the following url rewrites in the .htaccess folder:
RewriteEngine On
RewriteBase /clint/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /clint/index.php [L]
and
RewriteBase /magentoFolder/subStore
and
RewriteBase /magentoFolder/subStore/
and
RewriteBase /magentoFolder/
and
RewriteBase /subStore/
I have cleared out the var folder as well.
Any recommendations would be much appreciated.
Here is the code from line 133 in the resource.php file:
* Set module version into DB
*
* #param string $resName
* #param string $version
* #return int
*/
public function setDbVersion($resName, $version)
{
$dbModuleInfo = array(
'code' => $resName,
'version' => $version,
);
if ($this->getDbVersion($resName)) {
self::$_versions[$resName] = $version;
return $this->_getWriteAdapter()->update($this->getMainTable(),
$dbModuleInfo,
array('code = ?' => $resName));
} else {
self::$_versions[$resName] = $version;
return $this->_getWriteAdapter()->insert($this->getMainTable(), $dbModuleInfo);
}
}
It is not an apache error, it's a php error. Take a look at /var/www/vhosts/domain.com/magentoFolder/subStore/app/code/core/Mage/Core/Model/Resource/Resource.php, line 133
Maybe it's a database connection error.
i've a question on ko3 framework Pagination module.
I have a route template like this: http://my-site.com/blog/1/page2
Here's the code from my bootstrap.php file:
Route::set('blog', 'blog(/<id>(/page<page>))')->defaults(array('controller' => 'blog', 'id' => 1, 'page' => 1));
everything works nice, but Pagination library generates dirty urls like
http://my-site.com/blog/1/page3?kohana_uri=blog%2F1.
Here's the code that creates the pagination (in Controller_Blog)
$pag = Pagination::factory(array('total_items' => $total_posts, 'items_per_page' => 10, 'current_page' => array('source' => 'route', 'key' => 'page')));
$posts = $posts_model->selectPosts($section_id, $pag->offset, $pag->items_per_page);
$this->template->content = View::factory('html/blog', array('pag' => $pag));
How can I tell the Pagination module generate clean urls? When I remove trash from url manually, it works too.
Thanks in advance
Your .htaccess file has something like this in it: RewriteRule .* index.php?kohana_uri=$0 [PT] which is fine, but setting the kohana_uri GET parameter does absolutely nothing in Kohana 3.x. The rewrite should point to index.php/$0 or just index.php.