Codeigniter HMVC with ? in url after module - codeigniter

When I load my url with question mark ? it keeps on showing error page 404.
http://localhost/project-hmvc/admin/?route=common/dashboard
Module name is admin but need to be able to accept after module name ? it works fine if do not use question mark in url.
I have tried it with enable_query_strings true but does not work. So
not going to use it.
I have set route.
$route['admin/?route=common/dashboard'] = 'admin/common/dashboard/index';
All controllers have there first letter on file name and class uppercase.
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [NC,L]
Question: How can I make my codeigniter hmvc urls after the module name accept question mark ? with out enable_query_strings on config.php
Note: I have tried with $config['uri_protocol'] = 'QUERY_STRING'; no luck
Codeigniter version 3 running on windows 7 and xampp
modules >
modules > admin >
modules > admin > controllers > common
modules > admin > controllers > common > Login.php
modules > admin > controllers > common > Dashboard.php
modules > admin > views > template > login.php
modules > admin > views > template > dashboard.php

Related

Laravel url method post not point to project folder?

why my laravel url not working when method is post
example the url api must be : http://localhost/PROJECTNAME/api/loginWeb
but when i click post button it always direct to http://localhost/api/loginWeb
but when method is get this okay. i use xampp
here is my htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
When we're using session based laravel setup, all the route generator functions(url(), route()) use hostname http://localhost as root url, not http://localhost/PROJECTNAME. To resolve this issue please do following changes in laravel app.
Define APP_URL in .env file as APP_URL="http://localhost/PROJECTNAME"
Go to RouteServiceProvider which is located at app/Providers/RouteServiceProvider and force laravel to use APP_URL as root url for your app.
public function boot()
{
parent::boot();
// Add following lines to force laravel to use APP_URL as root url for the app.
$strBaseURL = $this->app['url'];
$strBaseURL->forceRootUrl(config('app.url'));
}
Same issue occurred to me when I used same domain and a suburl to identify different projects.
Linux: Nginx serves multiple apps with two different locations
Windows: Multiple Laravel Applications Using Nginx - Windows

How to setup routes for simple frontend routing

i'm a newbie in codeigniter.
I want to create a new page for the frontend - mynewpage.php.
The index.php in frontend will work fine.
So i do the following steps
In the Frontend.php Controller i add this
public function mynewpage()
{
$this->view = 'frontend/mynewpage';
$this->layout();
}
the mynewpage.php is still inside the "views/frontend/" folder
In the routes.php is this part for the frontend i think
$route['/'] = "frontend/";
$route['/(:any)'] = "frontend/$1";
This is inside my htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
AddDefaultCharset utf-8
So if i enter my webadress like
-> www.example.com the index.php will be display and the adressfield show www.example.com
-> if i try www.example.com/mynewpage.php i get Error 404 - Page not found
-> if i try www.example.com/mynewpage i get Error 404 - Page not found
-> if i try www.example.com/frontend/mynewpage.php i get Error 404 - Page not found
-> if i try www.example.com/frontend/mynewpage the page will be show
What i have to change or do that the mynewpage.php will be show on enter the adress without the "/fontend/" = www.exapmle.com/mynewpage and as mynewpage.php?
Thanks a lot
You need to write a route for your mynewpage, something like:
$route['mynewpage'] = "frontend/mynewpage";
right now you have a route for frontend, but frontend is your controller. No need to route that.
see more about CI URI Routing

Magento - Currency - 404 Not Found - The requested URL /directory/currency/switch/currency/USD/ was not found on this server

Recently I bought theme and now I have troubles with currencies.
When I switch the currency I got message like that:
The requested URL /directory/currency/switch/currency/USD/uenc/aHR0cDovL3ZvdmFuLm5pY2t3bGtlci5jb20v/ was not found on this server.
But if I go back I'll see that currency changed.
How to prevent this "error" ?
I found the solution.
I was needed to remove index.php from url in magento.
I did that:
1) System >> Configuration >> Web >> Search Engines Optimization >> Use Web Server Rewrites : YES
2) System >> Configuration >> Web >> Secure >> Use secure URL Frontend: YES
3) Then created the .htaccess file under my magento installed folder with this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Thanks for trying help me.

How to delete the name of the controller in the URL with CodeIgniter?

I have urls that all contain /main/ in the url as it is my main controller.
I'd like to get rid of it.
I understood in the User Guide that the routing class will only re-route my URL, not hide a part of it (it is segment 1 according to their docuementation).
Thus, I've found this:
$route['(:any)'] = "auth/$1";
But I have 404 errors (That's the only modification I made to routing.php)
I believe I'll have to do it in the .htaccess, but I don't know what should be the syntaxe for that. For now, my .htaccess is this one:
<IfModule mod_rewrite.c>
SetEnv MAGIC_QUOTES 0
SetEnv PHP_VER 5
# For security reasons, Option followsymlinks cannot be overridden.
# Options +FollowSymlinks -MultiViews
Options +SymLinksIfOwnerMatch -MultiViews
RewriteEngine On
DirectoryIndex index.php
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
I am using several controllers and my links are similar to this one :
Thanks
Try this:
$route['blog'] = 'blog'; // seem stupid but otherwise the (:any) route below will send it to main
$route['blog/(:any)'] = 'blog/$1'; // to have blog cotroller work
$route['blog/(:any)/(:any)'] = 'blog/$1/$2';
// repeat for other controllers
$route['(:any)'] = "main/$1";
$route['(:any)/(:any)'] = "main/$1/$2"; // if you use other uri parameter
$route['default_controller'] = 'main'; // to have your main page work...
And put before this directive all calls to other controller as this will prevent all other controller calls.

Codeigniter - no input file specified

I am a beginner in Codeigniter and I saw a CI tutorial and was just trying to do a simple thing. I downloaded the CI and added this file to controller directory, but it won't work.
<?php
class site extends CI_Controller
{
public function index()
{
echo "Hello World";
}
function dosomething()
{
echo "Do Something";
}
}
?>
When I try to access it using http://..../index.php/site I get the output ... "no input file specified" .... by the way, I named the file site.php
Just add the ? sign after index.php in the .htaccess file :
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
and it would work !
Godaddy hosting it seems fixed on .htaccess, myself it is working
RewriteRule ^(.*)$ index.php/$1 [L]
to
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
I found the answer to this question here..... The problem was hosting server... I thank all who tried .... Hope this will help others
Godaddy Installation Tips
RewriteEngine, DirectoryIndex in .htaccess file of CodeIgniter apps
I just changed the .htaccess file contents and as shown in the following links answer. And tried refreshing the page (which didn't work, and couldn't find the request to my controller) it worked.
Then just because of my doubt I undone the changes I did to my .htaccess inside my public_html folder back to original .htaccess content. So it's now as follows (which is originally it was):
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?/$1 [L,QSA]
And now also it works.
Hint: Seems like before the Rewrite Rules haven't been clearly setup within the Server context.
My file structure is as follows:
/
|- gheapp
| |- application
| L- system
|
|- public_html
| |- .htaccess
| L- index.php
And in the index.php I have set up the following paths to the system and the application:
$system_path = '../gheapp/system';
$application_folder = '../gheapp/application';
Note: by doing so, our application source code becomes hidden to the public at first.
Please, if you guys find anything wrong with my answer, comment and re-correct me!
Hope beginners would find this answer helpful.
Thanks!
My site is hosted on MochaHost, i had a tough time to setup the .htaccess file so that i can remove the index.php from my urls. However, after some googling, i combined the answer on this thread and other answers. My final working .htaccess file has the following contents:
<IfModule mod_rewrite.c>
# Turn on URL rewriting
RewriteEngine On
# If your website begins from a folder e.g localhost/my_project then
# you have to change it to: RewriteBase /my_project/
# If your site begins from the root e.g. example.local/ then
# let it as it is
RewriteBase /
# Protect application and system files from being viewed when the index.php is missing
RewriteCond $1 ^(application|system|private|logs)
# Rewrite to index.php/access_denied/URL
RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]
# Allow these directories and files to be displayed directly:
RewriteCond $1 ^(index\.php|robots\.txt|favicon\.ico|public|app_upload|assets|css|js|images)
# No rewriting
RewriteRule ^(.*)$ - [PT,L]
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php?/$1 [PT,L]
</IfModule>
One of my Codeigniter apps started returning this error after i restarted my server.
When I checked the Codeigniter error log it says something like:
"...[error] 879#0: *273 FastCGI sent in stderr: "PHP message: PHP Warning: Unknown: open_basedir restriction in effect. File(/pathToWebsiteRootFolder/index.php) is not within the allowed path(s): ".
So I added this:
open_basedir= /pathToWebsiteRootFolder/index.php:
To a user.ini file I created in my website root folder.
And this Solved it.
FYI: Im using an NGINX web server.
However, Its strange because I didn't have to do this for the other Apps on the same server.

Resources