Forum Moderators: phranque

Message Too Old, No Replies

htaccess + codeigniter double slash seo problem

         

canado

8:53 pm on Feb 24, 2015 (gmt 0)

10+ Year Member



Hello

Here is my problem

I have a codeigniter project working fine meaning the htaccess works. it display the pages etc ...

but when I tried my website to fetch as google

it appears I have too many redirects.
I found this webpage that better explain my problem

[link to tools snipped]

When I try this with my website I have

Final status code:: 302
19 Redirect(s)
http://example.com
302 redirect
http://example.com//metro
http://example.com//metro
302 redirect
http://example.com//metro
http://example.com//metro
[...]

which goes on and on : (


but visually when not checking my website as a google bot, the url is nice
example.com/en/montreal


here is my .htaccess


<IfModule mod_rewrite.c>


RewriteEngine On
RewriteBase /

RewriteRule ^(.+)/$ /$1 [R=301,L]

RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>



In my config file I tried all possibilities
here is my value

$config['uri_protocol']= 'AUTO';

and of course my index_page is

$config['index_page'] = '';



in routes

$route['default_controller'] = 'metro';


in metro controller

index

redirect(base_url().'Montreal', 'location', 302);


How can I get rid of this double slash right after the domain name ?

Thanks in advance

[edited by: phranque at 1:02 am (utc) on Feb 25, 2015]
[edit reason] Please Use example.com [webmasterworld.com] [/edit]

phranque

1:05 am on Feb 25, 2015 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, canado!


is there more to your .htaccess file?
are there any mod_alias or mod_rewrite directives in the server config (httpd.conf file)?
which version(s) of the url is being indexed by google?

lucy24

3:10 am on Feb 25, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What you need to do is open up Firefox with Live Headers. (There may be equivalents for other browsers.) Request one of the offending pages and record the exact redirects, step by step. You can save the result as a text file for later study.

Where are the // double slashes coming from? I had to deal with some recently-- as far as I can tell, google was simply inventing them out of its fevered imagination-- and made a nasty discovery. On my server, // in an URLpath isn't recognized in the body of a RewriteRule. I had to put it into a Condition instead.

Is it your own server? If so, is there a chance that requests will meet more than one source of redirects? mod_rewrite directives located anywhere other than htaccess should have no effect, thanks to wonky inheritance. But make sure there aren't any mod_alias directives (Redirect or RedirectMatch by those names) lurking around.

The very worst possibility is that the redirects are being created by codeigniter, meaning that it's been misconfigured in some really horrible way. But let's not borrow trouble.

canado

11:40 am on Feb 25, 2015 (gmt 0)

10+ Year Member



Well I have indeed something more in my htaccess

SetEnv PHP_VER 5_2

( I m on my way to port my project for codeigniter 3 )

If I look with charles's web debugging, all the redirection is correct
http://example.com/en/metro
StatusComplete
Response Code302 Moved Temporarily
ProtocolHTTP/1.1
MethodGET
Kept AliveYes
Content-Typetext/html
Client Address/127.0.0.1
Remote Addressexample.com/XXX.XXX.XXX.XXX
GET /en/metro HTTP/1.1

And then


URLhttp://example.com/en/montreal
StatusComplete
Response Code200 OK
ProtocolHTTP/1.1
MethodGET
Kept AliveYes
Content-Typetext/html
Client Address/127.0.0.1
Remote Addressexample.com/213.186.33.82
GET /en/montreal HTTP/1.1

Aside from that, no I don't have access to the httpd.conf file, it is hosted on OVH

About google, I don't have a status complete, in webtools but I have a status ( redirected )
My site is not indexed

with live headers verything looks fine

lucy24

6:25 pm on Feb 25, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Oh. Just ONE redirect? The first post led me to believe you were getting 19 redirects on a single request. Do you mean that they tried 19 different and unrelated URLs, and each one was redirected? Or is it that the googlebot-- only-- is getting handled in a different way? (Normally when people talk of "cloaking" they mean showing the search engine better content than what humans get. But showing worse content is of course just as bad, though probably not intentional.)

It should never be 302, though. Unless you've intentionally coded it: "Use the side door temporarily while we're painting". But redirects default to 302. So make sure the code-- wherever it is-- says "301" explicitly.

If /metro redirects to /montreal, why are you requesting /metro in the first place? Sure, you yourself might do it for testing purposes. But you need to make sure there are no internal links pointing to /metro. Search engines don't like links that lead directly to a redirect. (Neither do humans, if they're on a slow connection.) It may or may not be in your power to fix external links from other sites.

In my config file

What did you mean by "config file" here? codeigniter settings? Are you positive this is an Apache issue? From the outset it looked more like a php-internal misconfiguration.

canado

6:41 pm on Feb 25, 2015 (gmt 0)

10+ Year Member



So, as a browser point of view everything looks perfect
When fetching as google then I have the 19 more redirects

Once everything will be working I ll put back the 301 everywhere

As for the metro/montreal
I ll skip this in the future and just keep one big controller

But I m still stuck on http://example.com//metro : (


( config file, yes it was codeigniter config file )

canado

2:08 pm on Feb 27, 2015 (gmt 0)

10+ Year Member



Found it !

I m using a hmvc third party, and because the seo bot language is not detected instead of redirecting to http://example.com/en/metro it was redirecting to
http://example.com/[default language null]/metro
so
http://example.com//metro

I hardcoded "en" if default language is null