0

The code inside my .htaccess file is:

# Do not remove this line or mod_rewrite rules and search engine friendly URLs will stop working
RewriteBase /

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

Is this code all right?

I was told that this would ensure that I can access my files without typing .php in the browser. However, this is not the case. I'm using WampServer Version 2.5. I've already ensured that rewrite_module is turned on in the apache modules, and ensured it's on in httpd.conf. My port 80 is used by apache itself.

So why can't I access the page without typing the extension? I get a 404 Error when I try to do so.

EDIT : I tried the solution provided Here, with the new code being:

# Do not remove this line or mod_rewrite rules and search engine friendly URLs will stop working
RewriteBase /

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule !.*\.html$ %{REQUEST_FILENAME}.html [L]

But it still returns a 404 Error. Why is this happening? NOT FOUND. The requested URL /SomuFinanceAJAX/bill/billMaker/index was not found on this server.

Community
  • 1
  • 1
Somenath Sinha
  • 1,174
  • 3
  • 16
  • 35
  • The regexp doesn't allow a single dot anywhere within the requested URI. It's terrible logic. Use this solution instead: http://stackoverflow.com/questions/4026021/remove-php-extension-with-htaccess – Ultimater Dec 21 '16 at 09:58
  • @Ultimater Tried doing it. It still returns a 404 Error. Any ideas why? – Somenath Sinha Dec 21 '16 at 10:05
  • Change those `.html`'s into `.php`'s. – Ultimater Dec 21 '16 at 10:08
  • @Ultimater Already did that. Didn't work. The error i get is : `The requested URL /SomuFinanceAJAX/bill/billMaker/index was not found on this server.` – Somenath Sinha Dec 21 '16 at 10:10
  • Are you putting the .htaccess file in your web root? And can you verify your .htaccess is being processed by running some tests as mentioned here? https://docs.bolt.cm/3.4/howto/making-sure-htaccess-works – Ultimater Dec 21 '16 at 10:15
  • @Ultimater Already tested that. It's working. I've narrowed down the problem - WAMP 2.5 by itself suppresses the URL to omit localhost. The error is: The requested URL /bill/billMaker/index.php was not found on this server. Note the path: `/bill/billMaker/index.php`. It's missing the part about `localhost`. Maybe that's why the file isn't available? How do I fix this? – Somenath Sinha Dec 21 '16 at 10:19
  • 1
    It doesn't need the host to forward. Before you mentioned `/SomuFinanceAJAX/`. Perhaps you need to use `RewriteBase /SomuFinanceAJAX` – Ultimater Dec 21 '16 at 10:24
  • @Ultimater I had to remove the RewriteBase all together for it to work. Please suggest doing so in an answer so that I can upvote you and select it as the best answer. – Somenath Sinha Dec 21 '16 at 11:14

1 Answers1

1

As per the comments, the issue appears to be related to the RewriteBase. Remove the RewriteBase / altogether.

Ultimater
  • 4,647
  • 2
  • 29
  • 43