I am using MVC framework in my website.In my webpage URL file extension is not showing.I need to specify the file extension like
www.legacy.com/women/tops.php
but its showing only
www.legacy.com/women/tops/
for seo purpose I want to change the url with extension. But I can’t change the folder or file name.
One more doubt I have that.My webpage is showing
www.legacy.com/women/tops/
like this I want to change this as http://www.legacy.com/women_tops.php/
Is it possible?
Thank you
Here is the code I use to associate a URL with a controller:
$arrCommands = array (
'home' => "contents",
'members' => "",
);
if ( $arrCommands[$command1] == "*" )
{
$includeFile = CONTROLLER_PATH . "/" . $command1 . "/" . $command2 . ".php";
if ( !file_exists($includeFile) )
$includeFile = CONTROLLER_PATH . "/" . $command1 . "/default.php";
}
elseif ( !array_key_exists($command1, $arrCommands) )
{
$includeFile = CONTROLLER_PATH . "/contents/" . $command1 . ".php";
if ( !file_exists($includeFile))
Header( "Location: http://metroplots.ragedev/404_error/" );
}
else
{
$includeFile = CONTROLLER_PATH . "/". $arrCommands[$command1] . "/" . $command1 . ".php";
if ( !file_exists($includeFile) )
$includeFile = CONTROLLER_PATH . "/contents/home.php";
}
include_once($includeFile);
the technology your looking for is called url rewriting
the idea is taking a give url and rewriting it on the server side. lots of software use this method to not expose logic via get parameters…
e.g.
http://domain.com/blog/2
according to the server, this url is actually:
http://domain.com/index.php?cat=blog&page=2
on linux/apache servers is is achieved via modrewrite:
http://httpd.apache.org/docs/current/mod/mod_rewrite.html
using .htaccess files on the server that explain the rewrite rules and route urls.
microsoft iis servers have their own flavor (and syntax) called url rewrite:
http://www.iis.net/downloads/microsoft/url-rewrite
there are some tools out there to do this for you (here’s an overview of 6 of them)
http://webm.ag/2009/12/15/6-of-the-best-mod-rewrite-generators/
but i feel like most times your best best is to manually create your own.
here’s an example of the one i use on my site:
basically this ruleset will redirect all traffic to index.php
in my MVC i have a generic controller called “url_logic” that runs first and looks at what the url is. and based upon it’s logic it creates the necessary controllers to create the site (even if it’s a 404 error controller).
hope that helps get you started!
also, if your using windows .htaccess files are tough to work with. i suggest naming them
htaccess.txt and when you upload them to the server rename them there.