0

I have set up this website and it's working perfectly, however, extensions such as domain.com/dashboard will display a 404 but when I add .PHP at the back -> domain.com/dashboard.php it displays. Is there a way to make all the files display correctly without me adding .PHP at the end of each URL?

Thanks

Brun0L3z
  • 1
  • 2
  • Please provide your server configuration. – Gerald Schneider Aug 01 '22 at 06:14
  • Using the basic namecheap shared hosting with php7.4 as default – Brun0L3z Aug 01 '22 at 06:18
  • Please provide your actual configuration files, especially your rewrite rules. – Gerald Schneider Aug 01 '22 at 06:20
  • I actually got to this to work. There was no .htaccess file so I created one and then added the following lines of code: `RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php [NC,L]` – Brun0L3z Aug 01 '22 at 06:27
  • So, we can close this question as a duplicate to https://serverfault.com/questions/392821/rewrite-directory-names-to-php-files-with-htaccess – Gerald Schneider Aug 01 '22 at 06:32
  • @Brun0L3z With your solution, try requesting `/dashboard/anything`. See the following related question: https://serverfault.com/questions/989333/using-apache-rewrite-rules-in-htaccess-to-remove-html-causing-a-500-error – MrWhite Aug 01 '22 at 16:40
  • thanks @MrWhite I did check the solution and tried applying it in my case as seen below ``` RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.php -f RewriteRule !\.\w{2,4}$ %{REQUEST_URI}.php [L] ``` however, I still get the error of the second / so dashboard/anything gives a 404 and even /dashboard/ still gives a 404. Please help. NOTE: I have read everything 4 times over at https://serverfault.com/questions/989333/using-apache-rewrite-rules-in-htaccess-to-remove-html-causing-a-500-error – Brun0L3z Aug 02 '22 at 04:35
  • It is not normal behavior to redirect a request to `domain.com/dashboard` to `domain.com/dashboard.php` and I fear this could have unintended consequences. When a specific file is requested it should have it’s full name specified. If you request `domain.com/dashboard` then the assumption is that this is a directory and the server should look for a default file like `index.html`, `index.php`, etc. in that directory. What you describe happening is normal, expected behavior. – Appleoddity Aug 02 '22 at 05:20
  • Does this answer your question? [Rewrite directory names to php files with htaccess?](https://serverfault.com/questions/392821/rewrite-directory-names-to-php-files-with-htaccess) – bjoster Aug 08 '22 at 11:29

0 Answers0