Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

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 was trying to learn how to edit and make a .htaccess file using a tutorial found at corz.org, I copied an existing .htaccess file from another site on my localhost and pasted the following content in it the follow:

RewriteEngine on
RewriteRule ^(.*)\.html$ $a.php [NC]

I was trying to learn how to redirect HTML pages to some PHP page.

My questions are:

  1. I tried doing Right Click > New > Text Document > Renaming it '.htaccess'. It should work but it gave an error that I must provide file name. But when I pasted .htaccess file here it was pasted successfully... Why is this? the same rules should apply to .htaccess file and it should generate some error.
  2. I have pasted the exact code and checked for any space UN-intentionally left, but still internal server error 500 occurs. Why is this?

Note: I am using Microsoft Windows and Wamp version 2.2

share|improve this question
1) are you using windows? and are you in the shell? 2) maybe you have weird char (like bad copy and paste) – Book Of Zeus Feb 25 '12 at 0:03
i am using notepad for the purpose, and no shell – Zaffar Saffee Feb 25 '12 at 0:06
up vote 2 down vote accepted

I use this:

Options +FollowSymLinks
RewriteEngine On
#RewriteBase /

# check if the file don't exists then redirect
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)\.html$ $1.php [NC,L]

and it work fine, the $a should be $1

RewriteEngine On Enables the rewrite IF mod_rewrite is enable.

RewriteBase / Executes all the rules from the root (/) directory.

RewriteRule ^(.*).html$ $1.php [NC,L]

  • ^ means Start with
  • (.*) means everything. Although, I prefer using ([a-z0-9_\-]+) which only allows letters, numbers, underscores and dashes
  • $1 means the first matching regular expression that the rule find.
share|improve this answer
would you please expalin the code to help me learn my mistake? – Zaffar Saffee Feb 25 '12 at 0:06
used your code, but its not working – Zaffar Saffee Feb 25 '12 at 0:08
Absolutely, i'll update my answer – Book Of Zeus Feb 25 '12 at 0:08
1) is the .htaccess at the root? can you give me an example of the file you are calling? – Book Of Zeus Feb 25 '12 at 0:08
i have myweb folder (www\zaf) and i created .htaccess file here in zaf, now i have tried to paste the same file in (www) folder, but still same probelm..and two lined code is my htaccess file, as i am trying to learn it – Zaffar Saffee Feb 25 '12 at 0:12

Your Answer


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.