CodeIgniter core/URI.php script_name empty needle warning - codeigniter

I'm getting warning in my CodeIgniter Application.
A PHP Error was encountered
Severity: Warning
Message: strpos(): Empty needle
<!-- <p>Filename: core/URI.php</p>
<p>Line Number: 191</p> -->
<p>Line Number: 187</p> -->
My apache conf settings look like
RewriteCond $1 !^(index\.php|robots\.txt|fonts|assets|uploads|images)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
The code at CodeIgniter core/URI.php looks like
private function _detect_uri()
{
if ( ! isset($_SERVER['REQUEST_URI']) OR ! isset($_SERVER['SCRIPT_NAME']))
{
return '';
}
$uri = $_SERVER['REQUEST_URI'];
187 -> if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0)
{
$uri = substr($uri, strlen($_SERVER['SCRIPT_NAME']));
}
elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0)
{
$uri = substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME'])));
}
...}
It is obvious that SCRIPT_NAME is empty. However, why it is getting into line 187? isset() function would have returned right above. Isn't it?
I saw some answer that my Rewrite Conf might be the problem. However, I do not see anything wrong with it.
Please help me solve it out.
Thanks.
Happy New Year.

You need to put your rewrite rules in an .htaccess file rather than the VirtualHost section of your site conf file. isset() will still return TRUE for something set to an empty string. Either that or modify the core file to check if SCRIPT_NAME is set OR an empty string on line 181.
Apparently, this has something to do with an age old bug that is either Apache's fault or PHP's, but neither seems to accept responsibility. Putting your rewrite in an .htaccess file will properly set the SCRIPT_NAME to index.php.

Related

APIs Route in Laravel

I have a route like this in api.php:
...
Route::resource("infos",PaymentController::class)->only([
'show','store'
]);
...
And when I call my API like these:
/api/infos/ABC123 => success with Status Code: 200 (in access.log)
/api/infos/ABC123/ => there area 2 log (Status code: 301; then Status code 200)
/api/infos/ABC123//// => there area 2 log (Status code: 301; then Status code 200)
Why when I add slash symbols, there are 2 line in access.log?
Thanks!
The .htaccess file that ships with Laravel has a section in it that strips trailing slashes by using a redirect.
This is from the .htaccess file, which can be found here:
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
So, the first line you're seeing is the redirect triggered by this .htaccess code, and the second line is the final request without the slash.
Because when you add / then Laravel redirect it to address without /.

Nginx - URL rewrite rules

I have for example this URL:
www.example.com/folder1/folder2/edit.php?username=nickname
Actually I have this rewrite rules:
location / {
root /var/www;
index index.php index.html index.htm;
# First rewrite rule output: www.example.com/nickname
rewrite ^/([A-Za-z0-9_]+)$ /folder1/folder2/user.php?username=$1;
# Second rewrite rule output: www.example.com/nickname/edit
rewrite ^/([A-Za-z]+)/edit$ /folder1/folder2/edit.php?username=$1;
}
However, that works fine.
But I need to rewrite my URL like this:
www.example.com/nickname/edit/info
It has a couple of parameters:
www.example.com/folder1/folder2/edit.php?username=nickname&info=basic
I tried everything but with no success:
location / {
root /var/www;
index index.php index.html index.htm;
# First rewrite rule output: www.example.com/nickname
rewrite ^/([A-Za-z0-9_]+)$ /folder1/folder2/user.php?username=$1;
# Second rewrite rule output: www.example.com/nickname/edit
rewrite ^/([A-Za-z]+)/edit$ /folder1/folder2/edit.php?username=$1;
# Here where I'm stuck
# www.example.com/nickname/edit/info
rewrite ^/edit/([A-Za-z]+)/info$ /folder1/folder2/edit.php?user=$1&info=$2;
}
Your last attempt seems to have mixed up the location of edit. Also, nothing is passed to info as there is only one capturing group, perhaps
rewrite ^/([A-Za-z]+)/edit/([A-Za-z]+)$ /folder1/folder2/edit.php?username=$1&info=$2;
will work instead?

Redirect example.com/?p=25 to example.com/25 in CodeIgniter

I'm using CodeIgniter and I want to redirect links like this:
example.com/?p=25
to this:
example.com/25
How can this be achieved?
http://www.askaboutphp.com/58/codeigniter-mixing-segment-based-url-with-querystrings.html
or
to create url like this : http://yyyy.com/article/finishing-dan-snapshop-salkulator
add this code in routes.php
$route['article/(:any)'] = "article/readmore/$1";
description :
1. article : class name
2. readmore : method from class article
3. $1 : get value from uri segment 2 value
its .htaccess rewrite rule.make sure u have activated mod_rewrite .then put this line into website application root .htaccess file
RewriteRule ^/([0-9]+)/?$ p=$1 [NC,L] # Handle product
requests

Nginx rewrite rule with proxy pass

I'm trying to implement nginx rewrite rules for the following situation
Request:
http://192.168.64.76/Shep.ElicenseWeb/Public/OutputDocuments.ashx?uinz=12009718&iinbin=860610350635
Should be redirected to:
http://localhost:82/Public/OutputDocuments.ashx?uinz=12009718&iinbin=860610350635
I tried this with no luck:
location /Shep.ElicenseWeb/ {
rewrite ^/Shep.ElicenseWeb/ /$1 last;
proxy_pass http://localhost:82;
}
What is the correct way to perform such a rewrite for nginx ?
Your rewrite statement is wrong.
The $1 on the right refers to a group (indicated by paratheses) in the matching section.
Try:
rewrite ^/Shep.ElicenseWeb/(.*) /$1 break;
You're missing a trailing slash:
location /Shep.ElicenseWeb/ {
proxy_pass http://localhost:82/;
}
This will work without a rewrite.

How to write a url rewrite in nginx?

I want people type in http://www.myweb.com/like/1234456 will redirect to
http://www.myweb.com/item.php?itemid=1234456
I wrote something like this in the config but it doesn't work.
location = ^~/like/ {
rewrite ^1234456 ../likeitem.php?item=1234456break;
return 403;
}
this is just a test. I haven't used the $ matching yet.
I also restart my ngnix server but still.. it doesn't do the redirect.
The code above will not work because of a missing $ and poor use of the return command.
The code below works with Nginx, including version 0.8.54.
Format below is :
DesiredURL
Actual URL
Nginx_Rule
They must be inside location / {}
http://example.com/notes/343
http://example.com/notes.php?id=343
rewrite ^/notes/(.*)$ /notes.php?id=$1 last;
http://example.com/users/BlackBenzKid
http://example.com/user.php?username=BlackBenzKid
rewrite ^/users/(.*)$ /user.php?username=$1 last;
http://example.com/top
http://example.com/top.php
rewrite ^/top?$ /top.php last;
Complex and further
http://example.com/users/BlackBenzKid/gallery
http://example.com/user.php?username=BlackBenzKid&page=gallery
rewrite ^/users/(.*)/gallery$ /user.php?username=$1&page=gallery last;
Try this,
server {
server_name www.myweb.com;
rewrite ^/like/(.*) http://www.myweb.com/item.php?itemid=$1 permanent;
}

Resources