Code igniter - mod rewrite issue - .htaccess

I have following kind of URL,
http://example.com/controller/method/VBGFrt543ERik4523/text1-text2
I want this to be shown in browser as,
http://example.com/text1-text2
I searched a lot but couldnt find any specific solution on this requirement.
Can anyone help me out please?

Use URL routes with a bit of regex. This will reroute any url with letter and numbers followed by a hyphen and then letters and numbers to controller1/method/abc123/$1:
$route['([a-zA-Z0-9]+)-([a-zA-Z0-9]+)'] = "controller1/method/abc123/$1";
(nb. you only can have one controller in your URL - it goes controller/method/variable1/variable2...)
You set routes in application/config/routes.php
http://ellislab.com/codeigniter/user-guide/general/routing.html
Good luck!

Related

comma in the URL , google ignore all after comma

My site have links contains comma. eg. http://example.com/productName,product2123123.html
I set sitemap of this links and google webmaser tools report information that url is not found.
I see google ignore all after comma in url and try index http://example.com/productName that is error url and site generate 404.
Google have bug ? or i must change routing of my site ? or change comma to "%2C", but this could remove my actual offer from google ?
I'm not sure if this could help you but maybe this could help you understand more of what your problem is. Try reading the following links:
Using commas in URL's can break the URL sometimes?
Are you using commas in your URLs? Here’s what you need to know.
Google SEO News and Discussion Forum

Trying to create seo friendly url

I'm trying to create friendly url for my site but with no success :(( and i have two questions
The first is:
How to change the url from domain.com/page/something.php to domain.com/something
And the second is:
Will the changes make duplicate content and if how to fix the problem.
Thank you for your time,
Have a nice day
Check out the official URL Rewriting guide: http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
You'll be using the simplest use case, Canonical URLs. Assuming you have no other pages that you need to worry about, you can use a rule like this: (note: untested, your usage may vary)
RewriteRule ^/(.*)([^/]+)$ /$1$2.php
While that example might not exactly work for your use case, hopefully reading the guide and my example will help you get you on your way.

Codeigniter trying to get a specific URL pattern

I have two models called Lessons and Parts. Every lesson has many parts. I'm new to MVC and to Codeigniter but the desired URL is this:
example.com/lesson/2/part/3
I assume I'm supposed to do this with rewrite rules in either the .htaccess or the routes. I need help to get this right and an explanation of the rewrite rule or the route would be perfect.
Maybe Part is actually a method of the lesson's controller?
The CodeIgniter User Guide has a useful page on URI Routing.
You can do something like this to change it so that part is a method in the lesson controller:
$route['lesson/(:num)/part/(:num)'] = "lesson/part/$1/$2";
The guide is somewhat inconsistent in its inclusion of the brackets, so if that doesn't work then try this instead:
$route['lesson/:num/part/:num'] = "lesson/part/$1/$2";

Is it possible with canonical URL for this pattern in htaccess: /a/*/id/uniqueid?

A big problem is that I am not a programmer….! So I need to solve this with means within my own competence… I would be very happy for help!
I have an issue with a lot of duplicated URLs in the Google index and there are strong signs that it is causing SEO problems.
I don’t have duplicate links on the site itself, but as it once was set-up, for certain pages the system allows all sorts of variations in the URL. As long as is it has a specific article-id, the same content will be presented under an infinite number of URLs.
I guess the duplicates in Google's index has been growing over long time and is due to links gone wrong from other sites that links to mine. The problem is that the system have accepted the variations.
Here are examples of variations that exists in the Google index:
site.com/a/Cow_Cat/id/5272
site.com/a/cow_cat/id/5272
site.com/a/cow…cat/id/5272
site.com/a/cowcat/id/5272
site.com/a/bird/id/5272
The first URL with mixed case is the one used site-wide and for now I have to live with it, it would take too long time to make a change to all lower case. I cannot make a manual effort via htaccess as it is a total of 300.000 articles. I believe there are 10 ‘s of thousands that have one or more duplicates.
My question is this:
Is it possible to create rules for canonical URLs in htaccess in order to make the above URLs to be handled as one as well as for the rest of the 300.000?
I e, is there a way to say that all URLs having
/a/*/id/uniqueid
should be seen as one = based only on the unique ID and not give any regard to the text expressed with the “*”?
My hope is that it would be possible to say that a certain pattern like above should only be differentiated by the last unique segment.
If it is not possible in htaccess, how would it be done with link rel="canonical" on each page, can the code include wildcards?
I should add that the majority of the duplicates are caused by incoming links being lower case where the site itself is using a mix. Would it be OK to assign a canonical URL only with lower case although the site itself is basically always using a mix of lower/upper case?
If this is possible, I would be very happy to be helped with how to do it!!!!
Jonas
Hi Michael! I am not an expert but this is how I think it could be done:
1) My problem is that the URLs have mixed cases and I cannot change that now.
2) If it is OK for the searchengines, it would be fine for me to make the canonical URL identical to the actual URLs with the difference that it was all lower case, that would solve approx 90% of the duplicates. I e this would be the used URL: site.com/a/Cow_Cat/id/5272 and this would be the canonical: site.com/a/cow_cat/id/5272. As I understand, that would be good SEO...or...?
My idea was NOT to change the address browser address bar (i e using 301 redirect) but rather just telling the search engines which URLs that are duplicates, as I understand, that can be done by defining a canonical URL either in htaccess (as a pattern - I hope) or as a tag on each page.
3) IF, it would be possible to find a wildcard solution...I am not sure if this is possible at all, but that would mean it was possible to NOT assign a specific canonical URL but rather a "group pattern", i e "Please search engine, see all URLs with this patter - having the unique identifier in the end - as if they are one and the same URL, you SE, decide which one you prefer": /a/*/id/uniqueid
Would that work? It will only work in htaccess if canonical URLs can be defined as a group where the group is defined as a pattern with a defined part as the unique id.
Is it possible when adding a tag for each page to say that "all URLs containing this unique id should be treated the same"? If that would work it would look something similar to this
link rel="canonical" /a/*/id/5272
I dont know if this syntax with wildcard exist but it would be nice : )
My advice would be to use 301 redirects, with URL rewriting. Ask your webmaster to place this in your apache config or virtual host config:
RewriteMap lc int:tolower
Then inside your .htaccess file you can use the map ${lc:$1} to convert matches to lower case. Here, the $1 part is a match (backreference from brackets in a regex in the RewriteRule) and the ${lc: } part is just how you apply the lc (lowercase) function set up earlier. Here is an example of what you might want in your .htaccess file:
RewriteCond %{REQUEST_URI} [A-Z] #this matches a url with any uppercase characters
RewriteRule (.*) /${lc:$1} [L,R=301] #this makes it lowercase
As for matching the IDs, presuming your examples mean "always end with the ID" you could use a regex like:
^(.+/)(\d+))$
The first match (brackets) gets everything up to and including the forward slash before the ID, and the second part grabs the ID. We can then use it to point to a single, specific URL (like canonical, but with a 301).
If you do just want to use canonical tags, then you'll have to say what you're using code wise, but an example I use (so as not add tags to hundreds of individual pages, for instance) in PHP would be:
if ($_SERVER["REDIRECT_URL"] != "") {
$canonicalUrl = $_SERVER["SERVER_NAME"] . $_SERVER["REDIRECT_URL"];
} else if ($_SERVER["REQUEST_URI"] != "") {
$canonicalUrl = $_SERVER["SERVER_NAME"] . preg_replace('/^([^?]+)\?.*$/', "$1", $_SERVER['REQUEST_URI']);
}
Here, the redirect URL is used if it's available, and if not the request uri is used. This code strips off the query string (this bold bit in http://www.mysite.com/a/blah/12345/?something=true). Of course you can add to this code to specify a custom path, not just taking off the query string, by playing with the regex.

help with htaccess query strings appending constantly

I have an htaccess rule that goes:
RewriteRule ^Commercial-Units/For-Sale/(([a-zA-Z]+)*/([0-9]+)*/([a-zA-Z]+)*/([0-9]+)*/([a-zA-Z]+)*/([0-9]+)*)*$ pages/index.php?f=quicksearch&cust_wants=1&want_type=2&at=$3&start=$5&limit=$7 [R=302,L]
This is specifically designed for when a page requires paging records.
I have been trying to find solutions over everywhere in Google and Stackoverflow.com..
The problem is that everytime someone clicks on, say page 2, the address bar keeps on adding my query strings like so:
http://mysite.com/Commerial-Units/For-Sale/page/2/at/10/limit/7/page/2/at/10/limit/7
notice that the url above containes multiple key-value combinations duplicated and this goes on and on everytime someone clicks on the next page...
Hope someone can point me to the right solution to this...
Thank you very much!
Thats not a problem with your rewrite but with your site code the links are adding /page/2/at/10/limit/7 to the current url you need to remove the previous params using something like ../../../../../../page/2/at/10/limit/7
And if that is for SEO please use parameters for pagination, only use SEO friendly urls for categories and items, no need to index every single pagination option, as that will be duplicated content.

Resources