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)
Related
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
I am trying to rewrite the following Url for SEO and userfriendly purposes using htaccess or other solution. I have searched and found many answers but none gives me multiple parameters and i am not advance at this.
mysite.com/myfile.php?dept=1&prodid=161&user=2018&ulevel=1&parentcust=1&prodname=My widget
to
mysite.com/products/mywidget
if My Widget has spaces or apostrophes i need them removed. example the product Tiger's eye widget should be tigerseyewidget or tigers-eye-widget
You don't have to solve your problem with rewrites only.
For starters, let's strip your query string:
user id & user level do not belong there - it's dangerous to have these in your query string. What if I change it in my browser to user=1&ulevel=5 - am I then suddenly the administrator with access to all area's? Instead, work with sessions and store the user id & ulevel there
Do you really need the product id as well as the product name in the query string? I'd say: drop the product name, the id should be enough information for you to retrieve the product name.
parentcust: what is that? Do you really need it in the query string? What if I change the value? Looks like something that belongs in a session as well.
After stripping that, all you're left with is myfile.php?dept=1&prodid=161 - now that's something that's much easier to rewrite!
How to rewrite is another question. There are plenty examples on SO how to rewrite a query string based request to a "pretty url". Changing Tiger's eye widget to tigers-eye-widget is also well documented.
But.. who generates these links? If you generate these links, why not turn it around and link your products to e.g. mysite.com/tigers-eye-widget.html and then in PHP map "tigers-eye-widget.html" to product id 161 & dept 1?
Your problem should really only apply to legacy URL's that people may have bookmarked or still appear in search results. But for those cases it's perfectly acceptable to redirect them instead of rewriting them. So you can keep the mapping in a database or textfile, process the request with PHP and do a 301 redirect to the new URL - that way you tell search engines to replace the old URL with the new one and you don't have to worry about complicated multiple .htaccess rewrite rules.
I am currently working on a eCommerce style project that uses a search engine to browse 7,000+ entries that are stored in a database. Every one of these search results contain a link to a full description page. I have been looking into creating clean/slug URLs for this, my goal is if a user clicks on some search result entry the browser will navigate to a new page using the slug URL.
www.mydomain.com/category/brown-fox-statue-23432323
I have a system in place to convert a string / sentence into URL form. However, it is not clear to me what the proceeding steps are once these URL's are created. What is the general plan for implementing this system? Do the URL's need to be stored in a database? Am I suppose to be using post or get data from the search result page to create content in these full description urls?
I appreciate any suggestions!
Many thanks in advance!
Each product has a unique url associated with it in the database.
When you perform a search you just return the correct unique url.
That way you only ever work out what the url should be once, when the product is first added and that url will always relate to that one product. This is the stage you use your system to create that url
Maybe you can enlighten us as to if you are using a framework? Some frameworks (like Zend) have ini / xml files for routing. But you will still need to store the urls or at least the article slugs in a db.
Storing the entry urls in the db after they have been "searched" is necessary because you want slugs to stay the same for entries. This allows for better caching / SEO which will improve your sites usability.
Hope that helps!
Edit: Saw your question about pulling up individual articles. You will have to start by setting up a relation between your entries to urls in your database. Create a url table with url_id, and url. Then place url_id on the entry table. Then whenever someone goes to any URL search the url table for the current url, recall the url_id, and then pull the entry. At that point its just styling the page to make it look the way you want.
A common approach is to have a bijective (reversible) function that can convert a "regular" URL into a user-friendly URL:
E.g.:
www.mydomain.com/category/brown-fox-statue-23432323
<=>
www.mydomain.com/index.php?category=brown-fox-statue-23432323
Then you need not keep record of this mapping (convention vs. configuration).
Search StackOverflow for "User Friendly URL Rewriting" for information on how to achieve this automatically with Apache. This question is a good starting point.
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
Using Quora has made me wonder how they do their slug like thes : quora.com/topics-slugs , quora.com/questions-slug or quora.com/usernames-slug.
Actually i am developing an application with yii framework and i want to have a slugs like quora does?
Thanks guys
You can also do this with rewrite rules. A rule like this in your config file:
'controller/<slug:[\w\-]+>'=>'controller/view',
will take a URL like this:
controller/my-slug
and it will redirect to the actionView() in your Controller, and pass the slug ("my-slug") in as a $_GET variable. With that rewrite rule you now call $_GET['slug'] and it will return "my-slug" from the url.
I have a "slug" row as a primary key so then I just query the DB for $_GET['slug'] in my actionView() and I get the correct record based on the URL. Works like a charm. Good luck!
UPDATE
To get rid of the controller prefix in addition to using a slug, you will probably need one large table to keep track of all url slugs (to prevent duplicates). If you have that, then you could do a couple of different things:
1 Override onBeginRequest to do a lookup on the master slug table to figure out which Controller to call.
2. Use a master rewrite to a single ActionIndex in the SiteController, and in that action look up the slug in the master table to figure out which controller/action to send the user to. The rewrite rule would look something like this:
'<slug:[\w\-]+>'=>'site/index',
Handle any special characters you wanna use (Umlauts for example)
Remove any non-alpha-numeric-characters that are left
handle white spaces
Something like that for example:
function _getSlugFromName($name){
return preg_replace('#[\s]+#','-',preg_replace('#[^\d\w -]*#','',str_replace(array('ä','ü','ö','ß'),array('ae','ue','oe','ss'),html_entity_decode(mb_strtolower(trim($name),'UTF-8'),ENT_COMPAT,'UTF-8'))));
}
This may help you: dburlmanager
Provides dynamic database-based URL rules.
Dynamic URL rules based on database (pretty permalinks or friendly URLs)
These dynamic rules are like Wordpress' "pretty permalinks" or "friendly URLs". You do not have to have the controller name (or ID) on the URL: this extension can handle the request URI and route it to the correct controller.