Index.php 301 redirect

I want to redirect all calls to http://mydomain.com/index.php to
http://mydomain.com to avoid duplicate pages.I use this
if ($request_uri ~* “^/index.php??$”) {
rewrite ^.*$ http://$host? permanent;
}

but it doesn’t seem to work properly. Although it redirects I cannot
login or logout anymore in Joomla, it simply redirect to homepage
without login or logout. What am i missing here ? How do i do this
properly ? Of course if i remove that everything i fine, it works for
example for home.html but not for index.php.
Thank you.

On Wed, Oct 14, 2009 at 05:25:39AM -0700, SE7EN wrote:

I want to redirect all calls to Page Not Found to http://mydomain.com to avoid duplicate pages.I use this
if ($request_uri ~* “^/index.php??$”) {
rewrite ^.*$ http://$host? permanent;
}

but it doesn’t seem to work properly. Although it redirects I cannot login or logout anymore in Joomla, it simply redirect to homepage without login or logout. What am i missing here ? How do i do this properly ? Of course if i remove that everything i fine, it works for example for home.html but not for index.php.
Thank you.

The right way is to use

location = /index.php {
rewrite ^ http://$host? permanent;
}

However, if you have the following configuration:

location / {
index index.php;
}

location = /index.php {
rewrite ^ http://$host? permanent;
}

then the “/” request will be internally redirected to “/index.php”.
Therefore you should use something

location = /index.php {
if ($request_uri = /index.php) {
rewrite ^ http://$host? permanent;
}

   ...

}

How do login and logout URLs look ?

приветствую всех
подниму темку, столкнулся с этим
редиректом, при

location / {
index index.php index.html index.htm;
}

location = /index.php {
if ($request_uri = /index.php) {
rewrite ^ http://$host? permanent;
}
}

location ~ .php$ {

}
на запросы http://host.com и http://host.com/index.php
выводит исходник скрипта
товарищи, не подскажете, есть
какое-нить приемлемое решение ?
заранее спасибо

Posted at Nginx Forum:

On 07/02/2010 02:42 PM, garrotte wrote:

        rewrite ^  http://$host? permanent;
  }

seems like you need to add php handler in your (location = /index.php)
somesing like
fastcgi_pass … blah blah blah.

Роман, спасибо огромное !
стыдно, но мне это даже не пришло в
голову)

Posted at Nginx Forum:

I have the following configuration for vhost:

server {
listen 80;
server_name www.mydomain.com;

  #redirect www to non-www
        rewrite ^/(.*) http://mydomain.com/$1 permanent;


   }

server {
listen 80;
server_name mydomain.com;
access_log /home/mydomain/log/access.log;
error_log /home/mydomain/log/error.log;

        location /  {
    root   /home/mydomain/public_html/;
    index  index.php index.html;
    expires 30d;

    #stop image and files hotlinking
    location ~* ^.+\.(gif|jpg|png|swf|flv|rar|zip|jpeg|css)$ {
    valid_referers none blocked mydomain.com www.mydomain.com 

*.google.com *.yahoo.com;
if ($invalid_referer) {
return 444;
}
}

    #joomla sef url's
    if (!-e $request_filename) {
      rewrite  ^(.*)$  /index.php?q=$1  last;
      break;
            }
      }

    if ( $args ~ "mosConfig_[a-zA-Z_]{1,21}(=|\%3d)" ) {
    set $args "";
    rewrite ^.*$ http://$host/index.php last;
    return 403;
    }

    if ( $args ~ "base64_encode.*\(.*\)" ) {
    set $args "";
    rewrite ^.*$ http://$host/index.php last;
    return 403;
    }

    if ( $args ~ "(\<|%3C).*script.*(\>|%3E)" ) {
    set $args "";
    rewrite ^.*$ http://$host/index.php last;
    return 403;
    }

    if ( $args ~ "GLOBALS(=|\[|\%[0-9A-Z]{0,2})" ) {
    set $args "";
    rewrite ^.*$ http://$host/index.php last;
    return 403;
    }

    if ( $args ~ "_REQUEST(=|\[|\%[0-9A-Z]{0,2})" ) {
    set $args "";
    rewrite ^.*$ http://$host/index.php last;
    return 403;
    }



        # pass the PHP scripts to FastCGI server listening on 

127.0.0.1:9000
location ~ .php$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /usr/local/nginx/conf/fastcgi_params;
fastcgi_param SCRIPT_FILENAME
/home/mydomain/public_html/$fastcgi_script_name;
}

 Â

 }

I tried what you suggested but it doesn’t work or I didn’t add it
properly.
— On Wed, 10/14/09, Igor S. [email protected] wrote:

From: Igor S. [email protected]
Subject: Re: index.php 301 redirect
To: [email protected]
Date: Wednesday, October 14, 2009, 4:10 PM

On Wed, Oct 14, 2009 at 05:25:39AM -0700, SE7EN wrote:

I want to redirect all calls to http://mydomain.com/index.php to http://mydomain.com to avoid duplicate pages.I use this
if ($request_uri ~* “^/index.php??$”) {
    rewrite ^.*$ http://$host? permanent;
}

but it doesn’t seem to work properly. Although it redirects I cannot login or logout anymore in Joomla, it simply redirect to homepage without login or logout. What am i missing here ? How do i do this properly ? Of course if i remove that everything i fine, it works for example for home.html but not for index.php.
Thank you.

The right way is to use

   location = /index.php {
     rewrite ^ http://$host? permanent;
   }

However, if you have the following configuration:

   location / {
     index index.php;
   }

   location = /index.php {
     rewrite ^ http://$host? permanent;
   }

then the “/” request will be internally redirected to “/index.php”.
Therefore you should use something

   location = /index.php {
     if ($request_uri = /index.php) {
       rewrite ^ http://$host? permanent;
     }

     …
   }

How do login and logout URLs look ?