the_critic
the_critic

Reputation: 12820

Explanation of this .htaccess file

I have recently added a .htaccess file to my website root in order to achieve something I have already asked in this question:

Create blog post links similar to a folder structure

Now, the top answer was brilliant and it worked on localhost, however on my server it doesn't.

To be honest with you, I am not quite sure what these statements in the .htaccess mean exactly. I would be grateful if somebody could explain them line by line.

So this is what I have

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Upvotes: 0

Views: 56

Answers (2)

the_critic
the_critic

Reputation: 12820

The actual problem was that the rewrite was not enabled on my virtualhost. So I enabled it in my virtualhosts and everything works now.

<VirtualHost *>
             ServerName mysite.com
             DocumentRoot /var/www/html/mysite.com
        <Directory /var/www/html/mysite.com>
                Options FollowSymLinks
                AllowOverride all
        </Directory>
</VirtualHost>

Upvotes: 0

casraf
casraf

Reputation: 21684

<IfModule mod_rewrite.c>              # If the module for rewrite is available
RewriteEngine On                      # turn it on
RewriteBase /                         # set / to the relative root path
RewriteRule ^index\.php$ - [L]        # don't rewrite index.php and stop the rest of the rules
RewriteCond %{REQUEST_FILENAME} !-f   # if file does not exist
RewriteCond %{REQUEST_FILENAME} !-d   # and file is not a directory
RewriteRule . /index.php [L]          # show the index page instead
</IfModule>                           # close the IfModule clause

I suspect if it doesn't work on your server, that the root directory isn't set properly for the domain or server configuration. You'll wanna look into where the files are placed and how the httpd.conf is configured to use those paths.

Also, for next time Apache has a wonderful documentation on this module that should cover everything I've just said, in more depth.

Upvotes: 1

Related Questions