I am trying to prevent a 404 error and redirect when using mydomain.com/something
It throws a 404 error because the page something.php does not exist. I want it to submit to the index page so I can capture the value with php and use it in my app. I also want to combine this with removing the extension (.php) yet still being able to access the pages. For example, instead of mydomain.com/contact.php I want to be able to type mydomain.com/contact but still be able to use mydomain.com/something and have it submit that to the index page if the page something doesnt exist.
Hopefully someone can help me as I have tried a lot of different things and nothing seems to be working. The closest I have been able to get was by using the following htaccess code:
DirectoryIndex index.php
Options +FollowSymLinks
Options -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt|css|index|js|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ index.php?/$1 [L]
However, it seems like when the file doesnt exist and I just want the value to submit to the index page as a slash, it doesnt work and it hangs and eventually throws a 404.
Try this code in your
DOCUMENT_ROOT/.htaccess
file: