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.
Related
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.
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?
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
I moved from apache to lighttpd, and since then certain URLs break the rewriting and give 404. No details in access.log, error.log regarding what actual URL was hit.
These kind work:
http://192.168.1.250/loop/rest/admin
But not these:
http://192.168.1.250/loop/rest/admin/logs/file::log-2012-02-14.php
If I skip rewriting and use
http://192.168.1.250/loop/rest/index.php?/admin/logs/file::log-2012-02-14.php
I get what I want,
Here is my rewrite rule:
url.rewrite-once = (
"/(.*)\.(.*)" => "$0",
"/(css|files|img|js|stats)/" => "$0",
"^/([^.]+)$" => "/loop/rest/index.php/$1"
)
Any help would be appreciated.
I was just having the same issues when testing my codeigniter app on lighttpd
This worked for me:
url.rewrite = (
".*\.(js|ico|gif|jpg|png|swf|css|html)$" => "$0",
"^/(.*)$" => "index.php/$1"
)
maybe you could try this for your setup:
url.rewrite = (
".*\.(js|ico|gif|jpg|png|swf|css|html)$" => "$0",
"^/(.*)$" => "/loop/rest/index.php/$1"
)
Make sure you have uncommented mod_rewrite at the top.. it comes default with a # in front of it.
I have found the correct rules:
First of all please make sure that your root directive points to the root of your CI setupd.
root /var/www/loop;
Then this location directive will work perfectly fine:
location /
{
if (!-e $request_filename)
{
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}
}
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;
}