Welcome! Log In Create A New Profile

Advanced

Re: Help translating Apache RewriteRules

Chris Cortese
April 07, 2010 04:26AM
Thanks for the quick response Igor.

Unfortunately I'm still getting stuck in a loop.

This code which has been handed to me is using both the .htaccess rule
(shown below) and once it hits index.php (actually an include included
from index.php) it's also calling a PHP function named rewrite().

Maybe I can do some cleanup later but for now I really just want to be
able to run the site in my dev environment without having to install
Apache...

If the nginx rewrite rules will do what the one Apache rewrite rule
does, it really shouldn't matter what this following code does, I
wouldn't think.

[code]
/* rewrite url function */
rewrite();
if (isset($_GET['selectLanguage']))
{
if ($_GET['module'])
{
$reloadURL = $_GET['module'];
}
foreach ($_GET as $id=>$val)
{
if ($id != 'selectLanguage' && $id != 'module')
{
$reloadURL .= "/$id/$val";
}
}
header('Location: '.WWW_ROOT.$reloadURL);
}
function rewrite(){

/** URL rewriting action **/
global $_module;
if(isset($_GET['demand']) && $_GET['demand']!="") {

$_action_vars = explode('/', $_GET['demand']);

$_module = $_GET['module'] = trim($_action_vars[0]);

if(count($_action_vars) > 1) {
for ($i = 1; $i < count($_action_vars); $i += 2) {
if($_action_vars[$i] != ''){
if (isset($_action_vars[$i+1])) {

$_GET[trim($_action_vars[$i])] = trim($_action_vars[$i+1]);
} else {

$_GET[trim($_action_vars[$i])] = '';
}
}
}
}
} else {
// Setting default values for null request
$_module = $_GET['module'] = 'index';
}
unset($_GET['demand']);

foreach($_GET as $key => $val){
if($key == '' || $key == null)
unset($_GET[$key]);
}

/** End of URL rewriting action **/
}
[/code]


On 4/7/2010 1:05 AM, Igor Sysoev wrote:
> On Wed, Apr 07, 2010 at 12:25:37AM -0700, Chris Cortese wrote:
>
>> Hello,
>>
>> I've been using nginx for 1.5 years now with about 10 or so CodeIgniter
>> sites, but apparently I still haven't mastered the rewrite stuff.
>>
>> With the CodeIgniter stuff (and Igor's help), I never had to use the
>> "rewrite" command at all.
>>
>> Anyway, now I need to translate the following (from .htaccess for Apache):
>>
>> RewriteRule ^([0-9a-zA-Z\/\-\_\@]+)$ index.php?demand=$1 [QSA,L]
>>
>> My current conf file is going into a loop and eventually returning nothing:
>>
>> server {
>> listen 80;
>> server_name mysite.com.vmware;
>>
>> access_log /usr/local/nginx/logs/mysite.com.access.log;
>> error_log /usr/local/nginx/logs/mysite.com.error.log;
>>
>> root /home/mylinuxuser/www/live/mysite.com;
>> index index.php;
>>
>> rewrite ^/([0-9a-zA-Z\/\-\_\@]+)$ /index.php?demand=$1 last;
>>
>> location / {
>> fastcgi_pass 127.0.0.1:9000;
>> fastcgi_param SCRIPT_FILENAME
>> /home/mylinuxuser/www/live/mysite.com/index.php;
>> include /usr/local/nginx/conf/fastcgi_params;
>> }
>> }
>>
>> --------------
>>
>> Can someone please advise?
>
> location ~ ^/([0-9a-zA-Z\/\-\_\@]+)$ {
> fastcgi_pass 127.0.0.1:9000;
> fastcgi_param SCRIPT_FILENAME
> /home/mylinuxuser/www/live/mysite.com/index.php;
> fastcgi_param QUERY_STRING demand=$uri;
> include /usr/local/nginx/conf/fastcgi_params0;
> }
>
> location / {
> fastcgi_pass 127.0.0.1:9000;
> fastcgi_param SCRIPT_FILENAME
> /home/mylinuxuser/www/live/mysite.com/index.php;
> include /usr/local/nginx/conf/fastcgi_params;
> }
>
> fastcgi_params0 is copy of fastcgi_params without QUERY_STRING parameter.
>
>


_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

Help translating Apache RewriteRules

Chris Cortese April 07, 2010 03:30AM

Re: Help translating Apache RewriteRules

Igor Sysoev April 07, 2010 04:08AM

Re: Help translating Apache RewriteRules

Igor Sysoev April 07, 2010 04:10AM

Re: Help translating Apache RewriteRules

Chris Cortese April 07, 2010 04:26AM

Re: Help translating Apache RewriteRules - Again, Thoroughly

Chris Cortese April 08, 2010 04:52AM

Re: Help translating Apache RewriteRules - Again, Thoroughly

edogawaconan April 08, 2010 05:10AM

Re: Help translating Apache RewriteRules - Again, Thoroughly

Chris Cortese April 08, 2010 07:08AM

Re: Help translating Apache RewriteRules - Again, Thoroughly

edogawaconan April 08, 2010 09:28AM

Re: Help translating Apache RewriteRules - Again, Thoroughly

Chris Cortese April 08, 2010 02:24PM

Re: Help translating Apache RewriteRules

Chris Cortese April 07, 2010 04:26AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 119
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready