I have a problem fixing the URL on my website, http://www.abelputra.com: I want to change www.abelputra.com/software.php
into www.abelputra.com/software
.
I have read a tutorial that suggests the following:
For .htaccess:
RewriteEngine On
RewriteRule ^ ([a-zA-Z0-9_-] +) $ index.php? Key = $ 1
RewriteRule ^ ([a-zA-Z0-9_-]+)/$ index.php? Key = $ 1
Then in php:
index.php --->
$Key=$ _GET ['key'];
if ($key == 'home')
{
include ('index.php'); // Home page
}
else if ($ key == 'software')
{
include ('software.php'); //
}
else if ($ key == 'webdesign')
{
include ('webdesign.php'); //
}
The problem is that when I implemented the menu with software.php and index.php to call the page:
www.abelputra.com/index.php?key=software
what happens is that the page that's shown is two pages, with both software.php and index.php page underneath.
Is it because I'm calling "include ()" functions?
index.php structures:
Header
Content -> contains the opening words
Footer
software.php structure:
Header
Content -> contains an explanation of my software
Footer
I don't know if I understand correctly, but if you just want to rewrite the URLs (like removing the .php extension), you don't need to implement a gateway script or to change the logic code of your homepage (except modifying the URLs).
As an example, the following will allow to access your free tips with abelputra.com/freetips/185
RewriteRule ^freetips/(\d+)$ freetips_det.php?tip=$1 [L]
General extension removing is a well known topic, discussed here for example:
htaccess code to remove extension AND add+force trailing slash?
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]