How to achieve more semantic urls in code igniter? - php

I am just learning CI. I am trying to build my own CMS. I have successfully created a url structure www.mydomain.com/pages/getpage/2, where 2 is the id of the page.
However, I want to remove the '/pages/getpage/2' from the url. Instead, I want the domain to read www.mydomain.com/about, about being the title of the page, which is a column in the db.
I realise this is something to do with routing and maybe htaccess file.
I'm not sure what to put in routing to make the url as I want it.

If you want www.mydomain.com/pages/getpage/2 to route to www.mydomain.com/about, insert this line in to your routes.php
$route['about/(:num)'] = "pages/getpage/$1";
your URL structure will be www.mydomain.com/about/2, since you need that id as a reference to your content.
visit here for more details on routing

Related

How can I rename the WordPress AJAX URL?

I'm currently looking for a way to change / hide the default WordPress admin-ajax.php URL. I want to do this to remove the admin from it to prevent misunderstandings by my customers when I use the AJAX URL to read for example a file from my server. In this case, the URL has the admin prefix which is a bit confusing.
So in result the AJAX URl should looks like this: ajax.php
I've searched a bit but I can't find any helpful information. Because of this I can't show you any related code. But when I got it, I'll update my question to help other people.
Alternatively and perhaps more effectively you could leverage WP API and create a custom endpoint to process your data so that there isn't url confusion.

Having Post Name in the url without rewriting current url structure

Is it possible to have something like this in wordpress:
http://example.com/post/2135/post-name
without having to rewrite my current url structure which is
http://example.com/post/2135
I want to keep it, and be able to access posts both ways. With and without the post-name
is it possible to have it that way? maybe make wordpress ignore that there's the post name attached at the end?
i believe it is in the php.ini file
example,
me.com/boss
file structure
root/boss/index.php
the index.php file will auto load.
but if you are used MVC you can change the results of what is displayed.
but
can you use http://example.com.post/2135/index.php&postname=lol

Laravel Routing Database

I want to save some page information in database with url term that can be shown in URL when that page is going to access via URL. For eg. consider I have a website name as www.example.com
now I have page in my site say www.example.com/about-us.
Now I want to save the details of about us page in database say title, description and url_name
so if I update the content of about us page and set url_name as "something-about-us".
When I am accessing link from my website for About Us. so it should redirect to page with URL www.example.com/something-about-us instead of previous url www.example.com/about-us.
How I can create this kind of database saved routes in Laravel?
Thanks for help in advanced.
here is my thought. I don't think Laravel provides such a solution to your problem, though not 100% percent.
What you can do is to rewrite your own route file. Firstly, save information about dynamic routes in database and when they are updated, make sure that related database entries are modified accordingly.
Secondly, when requesting for a route, search the database and return url as parameter to redirect.
I am afraid you have to do it yourself just like construct apis using Laravel. If you have any question, I am ready to help.
I can't test it on this moment... but maybe you can do something like:
Route::get('user/{pageid}', function($pageid)
{
$page_content = //Search DB for page content with url_name = pageid;
return View::make('page.content', array('page_content' => $page_content));
});

SEO urls with kohana strategy

I want to use SEO urls in kohana, I already use htaccess file so I can have www.food.com/food/3123
Id:3123
title:hotdog
but thats not SEO friendly ,how would I get it to www.food.com/food/hotdog ? or www.food.com/food/I-love-hotdog ?
Searching DB with hotdog or I-love-hotdog is wrong right?
Ive read around some say do this www.food.com/food/3123/hotdog or www.food.com/food/hotdog3123 then parse it
Has anyone got the right way to do it? or better yet the structure?
Searching with "hotdog" or "I-love-hotdog" is rather OK. You can store additional field in DB table named "url" (for example). Note that "url" field MUST be uinique. Then in application/bootstrap.php create correct routes which will serve your requests taking url part of product and then search it in DB with controller.
Making http://stackoverflow.com/questions/10202703 automaticaly redirect to http://stackoverflow.com/questions/10202703/seo-urls-with-kohana-strategy is possible with Kohana's $this->request->redirect() (Request::redirect()) method. In controller you get the ID of item (in our example 10202703) then find corresponding URL (seo-urls-with-kohana-strategy) of item and redirect to $this->request->uri().'/'.$item_url by $this->request->redirect('/'.$this->request->uri().'/'.$item_url)

Take Unique id and use as url for page

I am building a website for sharing links and pictures for php experience. Currently, each post has a page where users can comment on it. Every post also has an id that is stored in a database with it. What would be the easiest way to make this id the url of the post? For example:
For the question that has an id of 4a3cd5, I would want the url for that question to be post.com/posts.php/4a3cd5. thanks for your answers.
In the HTAccess page (.htaccess), write the following code:-
Options +FollowSymLinks
RewriteBase /
RewriteRule ^posts/(.*)/$ /posts.php?id=$1
So now, in the Address Space, if you write http://localhost/posts/4a3cd5, the user will be shown a page corresponding to the post ID of 4a3cd5. Internally, the URL which will get processed is this one http://localhost/posts.php?id=4a3cd5. This whole technique is being done by HTAccess, and this way of showing URLs to users is called SEF URLs.
More on the HTAccess tips & tricks can be found here.
Now in the page "posts.php", you can write all the logic which you want using the PHP GET Superglobal Array "$_GET['id']".
NP: A special note - please try to avoid this type of coding. Instead try using any of the available standard PHP MVC Frameworks.
That would involve a lot, maybe you should just have URL's like /posts.php/?post=4a3cd5.
Overall this would be much more practical. You can just GET the post variable and connect to your SQL database.

Categories