1

My client has a website which already has a .htaccess file and some code in it. I need to add some redirects into it. However, I'm new to working with .htaccess and would want to be very careful to avoid messing up with the website. I do create a backup before uploading the changes.

Now, I'd like to understand what's already in there before I could make any changes. Because, I tried to copy-paste some code which I found online & it broke the website.

Let me get to the point. I see that the .htaccess file starts with:-

<IfModule mod_rewrite.c>

So, I'd like to understand 2 things:-

  1. Why do we need to check if mod_rewrite.c is there/enabled?
  2. How would I know if mod_rewrite.c is enabled in Apache or not...?

EDIT: My primary objective is to decipher the .htaccess file. So, please help me understand why the Ifmodule is used for mod_rewrite.c why can't we write the code directly?

cassiomolin
  • 124,154
  • 35
  • 280
  • 359
Anish K
  • 31
  • 1
  • 5
  • 3
    http://stackoverflow.com/questions/7337724/how-to-check-whether-mod-rewrite-is-enable-on-server – Rabea Dec 02 '15 at 13:44
  • Ifmodule is not required, its optional , you can write your htaccess code without ifmodule directive but you will get a 500 server error if mod_rewrite is disabled on your server. – Amit Verma Dec 02 '15 at 14:39

1 Answers1

1

Quiet simply you do this check so that you only add config that is related to mod_rewrite if that module has been activated in Apache.

If you were to try and add paramters that used mod_rewrite when it was not activated in Apache, Apache would crash and your server would be useless.

Making the check ensured you dont crash Apache, although it would of course not then have the mod_rewrite parameters applied to it either.

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149