Codeigniter URI Segment Not Working properly online - codeigniter

Please have a look at the following url:-
English: http://www.santinepal.com/demo/en
Nepali: http://www.santinepal.com/demo/np
The codeigniter profiler is ON but it shows
URI STRING
No URI data exists
The $this->uri->segment(1); shouldve returned en or np but it reruns nothing.
This works fine on my localhost.
my routes.php file has:-
$route['default_controller'] = 'front';
$route['backend'] = 'backend/sentry';
// URI like '/en/about' -> use controller 'about'
$route['^(en|np)/(.+)$'] = "$2";
// '/en' and '/fr' URIs -> use default controller
$route['^(en|np)$'] = $route['default_controller'];

Check that your .htaccess file is the same on the server and that URL Rewriting is enabled.
Navigating to http://www.santinepal.com/demo/index.php/en shows the URI segments working, so it must be server configuration issue.

I've had something similar, turns out some server setup caused the issue. Try changing your .htaccess file that removes the index.php to this:
#CODE IGNITER - REMOVE INDEX.PHP
RewriteCond $1 !^(index\.php|resources|file_uploads|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]
The last line is the only one that is different, there is a ? after the index.php.

Related

How to setup a Laravel app in a subdomain-directory in a shared host?

I want to access my Laravel application through a directory in a subdomain in a shared host; as in sub.domain.com/dir. I want to be able to properly hit the app routes as sub.domain.com/dir/posts.
Thus, I've set the APP_URL=https://sub.domain.com/dir/ in the .env file. It works through sub.domain.com/dir/public; but the relatively-addressed media are inaccessible; they are referenced as sub.domain.com/path/to/asset, while they should be sub.domain.com/dir/path/to/asset:
sub.domain.com/dir/path/to/asset <--- accessable: Expected
sub.domain.com/path/to/asset <--- inaccessable: What is given
In an attempt to drop the /public part, I've put the following code in an .htaccess file inside of <docroot>/dir directory:
RewriteEngine On
RewriteRule ^(.*)$ /dir/public/$1 [L,QSA]
It seems to be effective on dropping the /public part (let me know if there are issues with that).
Here is the main issue: considering the web.php file to be like:
Route::get('/{num}', function ($num) { return "Number: $num"; })->where('num', '\d+');
Route::get('/{any}', function ($any) { return "Other: $any"; })->where('any', '.*');
Accessing sub.domain.com/dir/123, gets Other: dir/123 instead of Number: 123: Laravel considers the /dir/123 as the routing matter, while I want it to treat the /123 as the routing matter. The same issue causes the assets to not to originate from sub.domain.com/dir but rather from the subdomain root: sub.domain.com, without the /dir suffix).
I want the sub.domain.com/dir to be considered as a whole (as if the /dir is part of the domain, in that the relatively-addressed media would be accessible); and what follows the /dir part, to be fed into Laravel app for routing and all the other stuff.
So, how should I setup my Laravel app in a subdomain-directory in shared host?
Put these lines of code in your laravel root directory .htaccess file, which might be in your sub.domain.com/dir directory.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
that will solve your /public problem.
For the Media assets, did you used the asset URL helper function to link the media assets?

Code Igniter doesn't recognize my function in controller under a folder

I have a folder under my main controller-folder called admin, in that controller i have a file name admin.php which has a function xyz.
I want to access that function using this url
http://localhost/webroot/admin/xyz
However when I try to access it, it is giving me this error.
404 Page Not Found
The page you requested was not found.
this is code of my routes.php file
$default_controller = "welcome";
$controller_exceptions = array('welcome','forum');
$route['default_controller'] = $default_controller;
$route["^((?!\b".implode('\b|\b', $controller_exceptions)."\b).*)$"] = $default_controller.'/$1';
$route['404_override'] = '';
$route['admin'] = "admin/admin";
This is my .htaccess file
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Also mod-rewrite is enabled :)
Please let me know why is it not working and how can i make it work. Any kind of help is really appreciated. Thanks
Ensure that your routes are stored in application/config/routes.php (not router.php as specified in your question). Try adding a route that uses a wildcard, like this:
$route['admin'] = "admin/admin"; //Routes to 'index()' function
$route['admin/(:any)'] = "admin/admin/$1"; //Handles all other cases
:any will match a segment containing any character(s), after the admin segment, and will pass it/remmap it to the the admin controller.
The user guide contains more information on controllers in sub-folders and routing.

CodeIgniter CSS File Not Included

I have a bit of an odd problem with my CodeIgniter installation, I am using modrewrite in order to shorten my URLs, for example I have an api page:
http://www.mydomain.com/api
And it works really well, my .htaccess file looks like this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
But whats really strange is if I type a trailing slash:
http://www.mydomain.com/api/
The API page loads ok but it doesn't include the Base CSS file which is included on all the pages, it would be fine if it didn't load anything at all, but I need to stop it from loading the actual api page. Any advice would be helpful,
Thanks!
UPDATE: I have found that when I view source my CSS file comes from the following when the CSS loads correctly:
http://www.mydomain.com/css/all.css
But when it fails to load it comes from
http://www.mydomain.com/api/css/all.css
Make sure that you have a trailing slash in your base_url in the config.php file:
$config['base_url'] = "http://www.mydomain.com/";
And always call the base_url() when dealing with links...etc
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>css/all.css">
EDIT:
Please note that I'm using the mod_rewrite from this wiki page BUT since my CI installation in not on the root (inside /ci173/) the RewriteBase is not / but /ci173/.
When using relative URL path like css/all.css or ./css/all.css (both are equivalent), you need to be aware that relative URL paths (like any relative URLs) are resolved using a base URL that is the URL of the current document if not specified otherwise.
So in your case /api or /api/ is the base URL path and the relative URL path css/all.css is resolved differently depending on the base URL path:
/api + css/all.css → /css/all.css
/api/ + css/all.css → /api/css/all.css
To conquer this you either need to
use absolute URL paths like /css/all.css that are independent from the base URL path
specify a different base URL in your HTML document (e.g. /); but note that this will affect all relative URLs and not just relative URL paths
adjust your relative URL paths to suite your base URL paths:
for /api use css/all.css
for /api/ use ../css/all.css
for /api/foo/bar/ use ../../../css/all.css, etc.
I guess the first solution is the easiest.

Ko3 - URL Rewriting problem - Removing index.php

I'm developing a website using Kohana 3 (1rst time I use a framework). Locally, everything works perfectly. At the moment, I have a default template controller, a multi-language support and my 'index.php' is correctly removed. So before going further, I tested if it worked on my server and I got an endless loop.
I followed the tutorial from the unofficial wiki for the multi-language implementation: http://www.kerkness.ca/wiki/doku.php?id=example_of_a_multi-language_website
A redirection to the default language occurs if the language is not specified in the uri so I figured the problem might have come from there even though it worked locally, so I removed it to see what happens without the redirection. Now, I can see my home page, but whatever the uri is in the web browser, the home page will always be called. I inserted the following line in my home view to check what the uri was:
request::instance()->uri() and effectively, the uri is always: /en/home/
I put the index.php back (in the bootstrap) and everything worked fine again, even with the redirection to the default language.
My first guess was that the uri isn't rewritten correctly, so I tried to change the .htaccess but no success...
Here's my .htaccess:
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /dev/
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
RewriteRule ^(application|modules|system)/ - [F,L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
(btw I also tried the other RewriteRule in the unofficial wiki, doesn't work either)
Additional info:
Host: WebHostingPad
Apache: v2.2.11
PHP: 5.2.9
Rewrite_Module is activated
Thank you, I would really appreciate your help because I've been trying to fix this for days now and it's really starting to annoy me ;)
The only thing you have to change in order to get rid of index.php in URL is to set the 'index_file' param in Kohana::init ( bootstrap.php ) to FALSE ( everything else can cause an error ).
So the Kohana::init looks like this;
Kohana::init(array(
'base_url' => '/',
'index_file' => FALSE,
));
If it worked with the original .htaccess, there's no need to change it at all.
The problem came from $_SERVER['PATH_INFO'] which returned no value...
This issue can be solved by adding the following line to the php.ini:
cgi.fix_pathinfo=0

form post to mod_rewrite url

I am trying to submit a form to the url "localhost/login". Inside my login directory I have an index.php file with the code I am using to debug that the post is working:
<?php
echo $_POST['username'];
?>
I have a .htaccess file inside my login directory:
RewriteEngine on
RewriteRule ^. index.php [L]
The problem is, when I post to localhost/login my firebug shows that the initial POST goes through, but then redirects to login.php as a GET request without any POST variables...
POST
http://localhost/login?password=test_password&remember=true&username=test_username
301 Moved Permanently
GET
http://localhost/login/
200 OK
Any tips would be great.
Thanks
I have a condition in my .htaccess file:
RewriteBase /
RewriteCond %{HTTP_HOST} !^www(.*)
RewriteRule ^(.*) http://www.%{HTTP_HOST}%{REQUEST_URI}
which rewrites any links without the prefix "www". Like this:
http://mysite.com to http://**www**.mysite.com
And that was the problem I had:
in my form I have forgotten to put the "www" and so my POST array was empty.
Putting the www in the form like this:
action="http://www.mysite.com/login"
instead of:
action="http://mysite.com/login"
fixed the problem for me.
Based on my research, POST should be allowed to be rewritten and come out as POST, any sort of problem is probably due to something else going wrong, like your code.
Btw, in general, to keep the GET parameters from being stripped, use the QSA directive:
[QSA,L]

Resources