0

I've recently bought a PHP script of a website. On the front page, whenever I click on login, or sign up or any other link, I get a 404 error (page not found).

The links are of the type: http://domain.com/login, http://domain.com/register, and so on, but when I check the file manager I found no folder named login or register, etc. Instead there are files like login.php and register.php and so on. Therefore when I rename the link to http://domain.com/login.php or /register.php, etc., it works!

Is there a way to correct this problem, apart from editing the links in all the files? Maybe something can be done by changing the .htaccess file.

P.S.: I use cpanel.

I checked my .htaccess file and found this (is there anything I need to edit in there?):

options -multiviews
<IfModule mod_rewrite.c>
RewriteEngine On 
RewriteBase /
RewriteRule ^users$ users.php
RewriteRule ^login$ login.php
RewriteRule ^logout$ logout.php
RewriteRule ^conversations/([^/.]*)?$ conversations.php?u=$1&%{QUERY_STRING}
</IfModule>
<IfModule mod_security.c> 
# Turn off mod_security filtering. 
SecFilterEngine Off 
# The below probably isn't needed, 
# but better safe than sorry. 
SecFilterScanPOST Off 
</IfModule>
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131

2 Answers2

1

You need to use a .htaccess file to rewrite the URL to remove the .php extension and redirect traffic to the correct scripts.

For more details, see an answer to Stack Overflow question Remove .php extension with .htaccess.

Community
  • 1
  • 1
Darren Coxall
  • 1,208
  • 11
  • 11
1

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

## Internally forward /dir/foo to /dir/foo.php
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
anubhava
  • 761,203
  • 64
  • 569
  • 643