Hi i have a site called finittra.com all menu's are dynamically linked with the page. I tried to make the site as like as a CMS. If i click on the about menu the url shows that http://www.finittra.com/?page=about & if i click on the contact page the url shows site url /?page=contact but i want that i would like to show everything within the finittra.com/finittra/ as like as a folder or canonical link type which is search engine optimization url friendly. Please anybody here to help me?
3 Answers
You might want to rewrite your URLs using .htaccess. You can use this mod-rewrite generator: http://www.generateit.net/mod-rewrite
Example:
RewriteEngine On
RewriteRule ^([^/]*)$ /?page=$1 [L]
But a proper & organized way would be using a Router, try Aura.Router
Example usage:
$routes = [
[
"name" => "My_route",
"pattern" => "/{page}",
],
[
"name" => "Another_route",
"pattern" => "/pages/{page}",
]
];
This is your routes array, the router will go through all routes and check if the given request url matches any of them.
$factory = new RouterFactory;
$router = $factory->newInstance();
foreach ($routes as $route) {
$router->add($route['name'], $route['pattern']);
}
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$match = $router->match($path, $_SERVER);
if ($match) {
$params = $match->params;
echo $params['page'];
}
URL to echo the page param: http://www.finittra.com/about
You will need to do the same as get for POST requests, but instead u'll need to add them manually to the url path. Atleast how I do it.
Comments
I'd try something like
RewriteEngine On
RewriteRule ^([a-zA-Z]+)/?$ index.php?page=$1 [L,NC,QSA]
This rewrites every finittra.com/xyz/ (which will be visible) to finittra.com/?page=xyz.
If you want your pages to have different names, you'll have to do that manually, I guess.
RewriteEngine On
RewriteRule ^finittra/?$ index.php?page=contact [L,NC,QSA]
Also, you have to adjust the links on your website
Comments
you must use .htaccess file in your project ,like :
.htaccess :
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^user/(\d+)*$ ./page.php?id=$1
If url request equl : http://www.finittra.com/user/123
Load :page.php?id=123