Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have this in my *.conf file ( I got this from someone else, not sure whether there is a bug or not), which I don't quite understand:

  RewriteEngine on
  RewriteBase /
  RewriteCond %{HTTP_HOST} mycompany.com
  RewriteRule ^$  http://mycompany.com/login   [L]
  # we check if the .html version is here (caching)
   RewriteRule ^$ index.html [QSA]
   RewriteRule ^([^.]+)$ $1.html [QSA]
   RewriteCond %{REQUEST_FILENAME} !-f

   # no, so we redirect to our front web controller
   RewriteRule ^(.*)$ index.php [QSA,L]

I roughly understand what it does; first it checks whether the incoming request is mycompany.com, if yes, then redirects to http://mycompany.com/login.

Then, what is the next condition to check? The fact that there is this

RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]

come before the RewriteRule ^$ http://mycompany.com/login [L] is confusing me.

Is there anyway to rewrite the above script in a RewriteCond, RewriteRule, RewriteCond, RewriteRule format?

share|improve this question

1 Answer 1

You have a ambiguous indentation of your configuration file.

Maybe the following is a bit clearer:

RewriteEngine on
RewriteBase /

# If the requested hostname is mycompany
# and no path segment was given,
# redirect to /login
RewriteCond %{HTTP_HOST} mycompany.com
RewriteRule ^$  http://mycompany.com/login   [L]

# Add .html extension to any requested filename.
RewriteRule ^([^.]+)$ $1.html [QSA]

# Check if requested filename (now with .html
# extension) exists,
# otherwise redirect to front controller
RewriteCond %{REQUEST_FILENAME} !-f  
RewriteRule ^(.*)$ index.php [QSA,L]

I removed

RewriteRule ^$ index.html [QSA]

because this could more easily be done with the DirectoryIndex directive.

share|improve this answer
    
OK, does this mean that if it's not redirected to /login, then it will add .html extension to any request filename, and only then proceeds to the last RewriteCond? –  Graviton Jan 1 '10 at 3:17
    
Yes, that's essentially what these RewriteRules do. –  joschi Jan 1 '10 at 14:09

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.