-1

I am trying to achieve url rewrite to remove php extension from the php files, but I cannot figure out what's wrong! I am using lampp on ubuntu machine and I even set the AllowOverride from none to All in httpd.conf:

# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
AllowOverride All   <--- I set it from "None" to "All"

and I have placed my .htacces file in the root of my project folder ie. projects/test/ (I don't even know this is right place the .htaccess file).My localhost url is like: http://localhost/projects/test/abc.php. I want it to be set as http://localhost/projects/test/abc.Here's my url rewrite code:

Options +FollowSymLinks -MultiViews

<IfModule mod_rewrite.so>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
</IfModule>

I even tried with <IfModule mod_rewrite.c>

nexuscreator
  • 835
  • 1
  • 9
  • 17
  • 1
    `I cannot figure out what's wrong!` and what can you figure out? What happens when you use your rules? What does your error_log and rewrite_log show you? is the mod_rewrite enabled within your loadmodules on the httpd.conf of your server? – Prix Jul 11 '14 at 14:40
  • Sorry for my ignorances, I am new to .htaccess stuff. As I said, I want to remove .php extension from abc.php. The problem is the browser still shows the url as http://localhost/projects/test/abc.php (which should have been rather as http://localhost/projects/test/abc). Sorry again, I don't know where to look for those log files you mentioned. – nexuscreator Jul 11 '14 at 14:50
  • With the current rule you are adding the `.php` extension instead of removing it. – feeela Jul 11 '14 at 14:58
  • Please use a search engine first, as this is a trivial task using mod_rewrite and it was solved a few thousand times before. – feeela Jul 11 '14 at 14:59
  • @feeela I'm following from the tutorial mention here: http://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/ and I've combined the code with different stackoverflow answers. Can you write the code for .php extension removal. – nexuscreator Jul 11 '14 at 15:06
  • Might be a bit basic, but as there is a typo in `.htaccess` in the subject line of the question, have you checked the file name is spelled correctly? – steveukx Jul 11 '14 at 15:32
  • @steveukx misspelt htaccess in the topic. The filename is ok. – nexuscreator Jul 11 '14 at 15:46
  • @nexuscreator it was worth a shot... – steveukx Jul 11 '14 at 16:00

1 Answers1

0

Just a guess, I would check that the Apache modules you need are enabled. mod_rewrite

http://httpd.apache.org/docs/current/mod/mod_rewrite.html

ZZ9
  • 2,177
  • 2
  • 27
  • 38
  • Using phpinfo(); the 'mod_rewrite' is mentioned in "Loaded Modules" section in apache2configuration. – nexuscreator Jul 11 '14 at 15:33
  • My bad, sorry, you mentioned this already. What I would do to troubleshoot is upload the site and the htaccess to hosted server by a thrid party that you yourself haven't configured and see if its an htaccess problem or an apache configuration problem – ZZ9 Jul 11 '14 at 15:47