Forum Moderators: phranque

Message Too Old, No Replies

htaccess puts an extra / on SOME links ;-(

         

Dexie

10:13 am on Feb 24, 2005 (gmt 0)

10+ Year Member



Hi all,

I have been through the threads and charter on it, but this one hasn't been covered anywhere as far as I can tell.

If you have this in your htaccess:

redirect 301 /example/ [mysite.com...]

and in Google, your site is mentioned as:

www.mysite.com/ example/

when the visitor clicks on it they get:

[mysite.com...]

I'm under the impression, through reading many threads here on these excellent forums, that it's good to end on a / as this is slightly quicker for the visitor, but in the above example, it causes the error shown. A lot of the visitors to the website are on dialup, so speed is very important.

Looking through Googles links to us, some of them end with / and some of them don't.

Is there any way that a rule can be done, so that it doesn't put an extra / at the end if there's already one?

If you need any more info to be able to help, please let me know. I've been battling with this for a few weeks and could really do with a hand ;-)

Sev.

jdMorgan

2:09 pm on Feb 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If that line of code is the only code that processes the request, then this won't happen. There is some other code in .htaccess or httpd.conf that is causing this problem.

Jim

Dexie

3:36 pm on Feb 24, 2005 (gmt 0)

10+ Year Member



Many thanks for the input Jim,

I've been all through the code in the .htaccess file and can't see anything else that would cause it ;-(

If it's any help, when I put this:
redirect 301 /example/ [mysite.com...]

I don't end up with // at the end of the url?

Also, am I right in saying that the visitor gets the new page quicker if there's a / at the end? Very important as the users are mostly on dialup.

Your helps appreciated.

Sev.

Dexie

8:13 am on Mar 1, 2005 (gmt 0)

10+ Year Member



Hi again Jim,

Been through it all thoroughly again and all I can see that might cause a problem, is that in Google, they have this:

[mysite.com...]

and this:

[mysite.com...]

So, to cover that, I have this in my .htaccess:

redirect 301 /oldexample/ [mysite.com...]

redirect 301 /oldexample [mysite.com...]

when the visitor clicks on it they should get:

[mysite.com...]

But the problem, is that if they click on the wrong one in Google, they get:

[mysite.com...]

Also, am I right in saying that the visitor gets the new page quicker if there's a / at the end? Very important as the users are mostly on dialup.

Looking through Googles links to us, some of them end with / and some of them don't.

If you need any more info to be able to help, please let me know. I've been battling with this for a few weeks and could really do with a hand ;-)

Any help appreciated.

Sev.

jdMorgan

2:55 pm on Mar 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, I'm afraid that is the cause of your problem. Those directives are incorrect.

A review of the Redirect documentation [httpd.apache.org] will explain the reason; Redirect uses prefix-matching, not exact matching.

I'd suggest deleting them and using:


RewriteRule ^oldexample/?$ http://www.mysite.com/newexample/ [R=301,L]

or, alternatively,

RedirectMatch 301 ^/oldexample/?$ http://www.mysite.com/newexample/

These are entirely equivalent; The first uses mod_rewrite, while the second uses mod_alias.

Yes, the user gets the page faster if a redirect is not required. A 301 redirect response terminates the current client HTTP request, and instructs the client to re-request the desired resource at the new URL included in that response. So the browser has to issue a second HTTP request to get the content it requested from the incorrect URL.

However, once you have a proper 301-redirect in place, this problem will go away in a few weeks, since the search engines will update the URLs they show for your site to include the trailing slash.

Jim

Dexie

2:24 pm on Mar 7, 2005 (gmt 0)

10+ Year Member



Hi Jim,

Many thanks for this help, I tested it for one of the old files and it works brilliantly - just got to change the rules for the other 50 ;-(

I decided to go for the rewrite option.

Thanks again.

Sev.

Dexie

2:08 pm on Mar 10, 2005 (gmt 0)

10+ Year Member



Hi again Jim,

Don't worry, all of the advice you gave was just perfect ;-), but I'm just a little curious about this particular one, as I can't seem to get it to work ;-(

Not sure if there's anything that anyone can do about this, but in my awstats I get a heck of a lot of 404's
on:

/example%20example

But when I put this in my .htaccess:

RewriteRule ^/example%20example/?$
[newsite.com...] [R=301,L]

It doesn't solve the problem, even though the same thing definitely works with the other 'error' pages?

Any ideas how I can get it to work at all please?

All the best.

Sev.

jdMorgan

6:42 pm on Mar 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You'll need to escape the "%" in "%20" because otherwise it wil be treated as a mod_rewrite back-reference to "%2" follwed by a literal "0". So change "%20" to "\%20".

Jim

Dexie

12:11 pm on Mar 26, 2005 (gmt 0)

10+ Year Member



Hi Jim,

Been very pleased with what you explained to me earlier ;-) But, 1 particular rule is really causing a problem, before I really got to grips with file names, I had a heavily hyphenated one, that is still in some SE's and when I put this in the .htaccess, it doesn't work:

RewriteRule ^example-example-example-example.html
[example.co.uk...] [R=301,L]

But this one does:

RewriteRule ^example-example-example.html
[example.co.uk...] [R=301,L]

Do you know if there's another way to it all please?

All the best.

Sev.