Disable url correction / rewriting by codeigniter for SEO - codeigniter

I have CI 1.6 installed, with basic url library and usual config/routes.php file.
But in my case all of the following urls works:
mysite.com/products/id/919330
mysite.com/products/id/919330/
mysite.com//products/id/919330 - (see double slash!)
mysite.com/products///id/919330/ - (even this!)
As my SEO-guy says that i need to redirect them all to the first variant
mysite.com/products/id/919330 or to give 404 by all except the first one.
Where i could try to make corrections to disable this clever URL detecting by CI?

Try this
$url = $this->uri->segment(n);
if($url[0]=="products" && $url[1]=="id"){
// Do this stuff;
}else{
// redirect to 404;
}
For futher information Check this

Related

How to redirect to url in laravel 5.0

i am using laravel 5 on local on window ..i am trying to redirect the page to some external url..but nothing seems to help me..
i tried
return \Response::make('',302)->header('Location','http://site2');
return redirect()->away("http://site2");
\Redirect::to('http://site2');
header('Location: http://site2');
but none of them working..gives no response..
Something like this :
return redirect()->away('http://site2');
Make sure you also add a return (i.e. return $this->checkSession();) in start().

NGINX Rules redirect with query string not working

We are trying to redirect all the files that have this format:
ajax/(.*).php
towards
ajax/getfile.php?file=$1
We always get 404 not when testing ajax/somefile.php found but we discoverd that by adding a trailing slash the rule works:
ajax/somefile.php/
The rule we have so far is:
location /ajax {
rewrite ^/ajax/(.*).php/?$ /ajax/getfile.php?file=$1;
}
The weirdest thing is that we have a similar scenario that actually works!
location /javasc{
rewrite ^/javasc/(.*).js/?$ /javasc/view.php?file=$1;
}

building custom url validator - how to grab new url out of a 'moved' url response?

so I do this
require 'net/http';
require 'net/smtp';
res = Net::HTTP.get_response(URI.parse("http://www.cifs.dk"));
and res.response.msg tells me 302 - the site has moved.
How do I get the full address that it was moved to? (http://www.cifs.dk/en)
res.methods shows me a bunch of things to try but no luck yet.
The closest I've found is
res.response.body, but that just gives me
... </h1>This object may be found here ...
which would be no fun at all to try to piece together.
The Location header is what you are looking for:
response['Location']

url::to(xxx/yyy) returns different results depending on context

I'm using the URL::to call to embed a link in an outgoing mail message. What I get when I do this is something like: "baseroot/public/index.php/xxx/yyy".
And yet when I do the same call, for example, within a route call, I get "baseroute/xxx/yyy".
Any idea?
The source of URL::to resides at
http://laravel.com/api/source-class-Illuminate.Routing.UrlGenerator.html#76-98
(linked to from http://laravel.com/api/class-Illuminate.Routing.UrlGenerator.html).
I suggest you add debug printing to your copy and see what values $this->getScheme() and $this->getRootPath() yield. These must be the source of the discrepancy, apparently caused by different this objects.
I had a very similar problem with URL::to('user/123') returning an incorrect value when visiting the homepage vs. another page. After some investigation, in my case it was a matter of case-sensitivity (!) in the request's url. I hope it's somehow related to your mysterious case.
More about my case: URL:to('user/123') gave me different results whether I visited http://localhost/MyApp/public/someurl or http://localhost/Myapp/public/someurl. In the former it gave the correct result http://localhost/MyApp/public/user/123, while the latter gave the wrong result of http://localhost/user/123.
.
From here, less important notes from my investigation, for future Laravel archaeologists. I hope I'm not talking all nonsense. I am new to Laravel, using a local Laravel 4 installation + WAMP on a Windows machine.
UrlGenerator's to() method uses $root = $this->getRootUrl($scheme);. The latter uses $this->request->root();, where request is \Symfony\Component\HttpFoundation\Request.
Request::root() indeed defaults to a wrong value e.g. http://localhost when visiting someurl with the incorrect case.
The culprit is Symfony\Component\HttpFoundation\Request (in vendor\symfony\http-foundation\Symfony\Component\HttpFoundation\Request.php). Its getBaseUrl() calls prepareBaseUrl(), and there the actual logic of comparing the requestUri with the baseUrl is finally performed.
For the few archaeologists still following, in my case the $baseUrl was /MyApp/public/index.php while the $requestUri was /Myapp/public/someurl, which sadly led the code to not satisfy this conditional:
if ($baseUrl && false !== $prefix = $this->getUrlencodedPrefix($requestUri, dirname($baseUrl))) {
return rtrim($prefix, '/');
}

get application path codeigniter with out contents after last slash

hi i am using codeigniter in my application .
for my application i need application path only before the last slash
like this
if application path is
http://localhost/elephanti/connections/fb_connection/invite_friends
i want to get
http://localhost/elephanti/connections/fb_connection
it is for a plae like this
echo "<script type='text/javascript'>top.location.href = '"+APPPATH+"'testapp';</script>";
i tried to use '"+APPPATH+"'../testapp' but could not , please help ...................
If you know the last part will always be the 4th, you can use a "dirty way" like this:
$url = site_url($this->uri->segment(1).'/'.$this->uri->segment(2).'/'.$this->uri->segment(3));
And then:
echo "<script type='text/javascript'>top.location.href = '".$url."'/testapp';</script>";
// here, though, I don't understan how "testapp" goes into the url..as a segment?
This will create a valid CI url using only the first 3 segments.
Alternatively, you can use the uri_string() function, wich returns only the segment part of the url. On this, you can explode/str_replace/array_pop/do whatever you need to and pass the new elaborated string on the site_url() function wichi will build the correct URL for you.
I don't understand what "testapp" is there or, do you want to substitute the last segment of your url with that? So that you have, in your example, http://localhost/elephanti/connections/fb_connection/testapp ?
Keep in mind that both uri_string() and site_url() are functions from the URL helper so you need to load it.
In Codeigniter APPPATH referes to the location on the disk and not the url of the application. What you are looking for is base_url(). base_url() return the base location of your site, which usually is the domain.
Concatenation in php is done with the dot operator: "."
echo "top.location.href = '".base_url()."'testapp';";

Resources