Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to set up CodeIgniter from an existing site that's on nginx. My local machine is Apache and this is the redirect scheme on nginx. How do I write this using RewriteRules?

    if ($host ~* ^www\.(.*)) {
            set $host_without_www $1;
            rewrite ^(.*)$ http://$host_without_www$1 permanent;
    }
if ($request_uri ~* ^(/welcome(/index)?|/index(.php)?)/?$){
            rewrite ^(.*)$ / permanent;
    }
if ($request_uri ~* index/?$){
            rewrite ^/(.*)/index/?$ /$1 permanent;
    }
if (!-d $request_filename){
            rewrite ^/(.+)/$ /$1 permanent;
    }
if ($request_uri ~* ^/system){
            rewrite ^/(.*)$ /index.php?/$1 last;
            break;
    }
if (!-e $request_filename){
            rewrite ^/(.*)$ /index.php?/$1 last;
            break;
    }
share|improve this question
up vote 1 down vote accepted

Something like this:

# These go in the VirtualHost context.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1$1 [R=301,L]

RewriteCond %{REQUEST_URI} ^(/welcome(/index)?|/index(.php)?)/?$ [NC]
RewriteRule ^ / [R=301,L]

RewriteRule ^/(.*)/index/?$ /$1 [R=301,L,NC]

RewriteCond %{REQUEST_URI} ^/system [NC]
RewriteRule ^/(.*)$ /index.php?/$1 [L]

<Directory /path/to/docroot>
    # This is so that these have the correct filesystem path in the
    # REQUEST_FILENAME parameter.
    # If you already have a <Directory> for here, add these to it.

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ $1 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^/(.*)$ /index.php?/$1 [L]
</Directory>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.