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:

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

  • 1) are you using windows? and are you in the shell? 2) maybe you have weird char (like bad copy and paste) Commented Feb 25, 2012 at 0:03
  • i am using notepad for the purpose, and no shell Commented Feb 25, 2012 at 0:06
  • There's nothing in that .htaccess snippet itself that would trigger a 500 error, except maybe if mod_rewrite is not enabled or something? Whenever you get a 500 error you need to check the server's error log for the details of the error. ($a would just be seen as a literal string.)
    – MrWhite
    Commented Jan 25, 2017 at 16:26

1 Answer 1


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 works fine, the $a should be $1.

  • RewriteEngine On Enables the rewrite engine IF mod_rewrite is enabled.

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

RewriteRule ^(.*)\.html$ $1.php [NC,L]
  • ^ means Starts 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 found.
  • would you please expalin the code to help me learn my mistake? Commented Feb 25, 2012 at 0:06
  • used your code, but its not working Commented Feb 25, 2012 at 0:08
  • Absolutely, i'll update my answer Commented Feb 25, 2012 at 0:08
  • 1) is the .htaccess at the root? can you give me an example of the file you are calling? Commented Feb 25, 2012 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 Commented Feb 25, 2012 at 0:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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