0

I'm having trouble using .htaccess. This is the content of my .htaccess file

RewriteEngine On RewriteCond %{REQUEST_FILENAME}!-d RewriteCond %{REQUEST_FILENAME}!-f RewriteRule ^([^.]+)\.php$ $1 [L] 

I opened up a text file, pasted these lines and saved it as .htaccess It was showing .htaccess before i right clicked the .htaccess file and changed it to "open with notepad". I guess that shouldn't make a difference but now its showing a blank name.

The main problem is when i open my localhost on the browser through wamp, the folder where I've kept the .htaccess file, isn't visible or if i access it shows this internal server error.Now, if i remove the .htaccess file from there, it shows up in the localhost directory and doesn't show an error when i try to open it.

4
  • 1
    check if mod_rewrite is enabled. Commented Jan 28, 2012 at 12:53
  • Okay,i enabled mod_rewrite and it has started showing the folder containing htaccess but i can still see .php extension Commented Jan 28, 2012 at 12:56
  • @Prateek What do you want your end users to see? Normally, the idea is that your user enters example.com/somepage and that is translated invisibly to somepage.php. The links on your site should be changed not to include the .php extension, and your users won't see them. Commented Jan 28, 2012 at 13:02
  • 1
    Oh. My bad i thought if i type in something like index.php it'll be shown as index, but i guess it works the other way round. It worked. Thanks a lot Michael. Commented Jan 28, 2012 at 13:36

1 Answer 1

1

If you're getting the 500 Internal Server Error, your .htaccess file is being read. From what I see, you may be missing spaces before the !:

 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d #-----------------------------^^ RewriteCond %{REQUEST_FILENAME} !-f #-----------------------------^^ RewriteRule ^([^.]+)\.php$ $1 [L] 

But if you want your users not to see the .php extension, the RewriteRule is backwards. The first part should not contain the .php:

 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f # The input URL has no PHP, but internally is served as .php RewriteRule ^([^.]+)$ $1.php [L] 
Sign up to request clarification or add additional context in comments.

1 Comment

Still wont show the folder where the htaccess file is placed and yes it shows the 500 internal server error. removed the space before the !. didnt work.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.