Forum Moderators: phranque

Message Too Old, No Replies

canonical urls with folders

         

cheaperholidays

10:44 am on Aug 22, 2006 (gmt 0)

10+ Year Member



Hi all,

i wonder if anyone can help kiss kiss

In our htaccess file we have the following
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blah\.com$ [NC]
RewriteRule ^(.*)$ [blah.com...] [R=301,L]

which does its job until you get this:-

www.blah.com/late-deals/ how do we add the intruction to follow the the dash and convert the url.

What happens at the moment is the url stays the same ie
www.blah.com/late-deals/

Insted of converting to [blah.com...]

Many thanks

Pete

jdMorgan

12:26 pm on Aug 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The function of the code you have is redirect requests for blah.com/<anything> to www.blah.com/<anything>, so your "problem report," as written, is not consistent with the posted code.

The last two URLs in your description are identical, so I don't know how you'd expect to redirect from one to the other.

There is nothing special about the "dash", so I'm not sure what the problem or question is...

You can shorten the code and proof it against breakage when a port number is appended to the hostname by using:


RewriteEngine on
RewriteCond %{HTTP_HOST} ^blah\.co[b]m[/b] [NC]
RewriteRule (.*) http://www.blah.com/$1 [R=301,L]

but that has nothing to do with the issue you are apparently trying to address.

Jim

cheaperholidays

9:06 am on Aug 23, 2006 (gmt 0)

10+ Year Member




Hi Jim

You wrote <The last two URLs in your description are identical, so I don't know how you'd expect to redirect from one to the other.>

I thought we had set up a canonical url the 2 urls are not the same

If someone types in www.blah.com/late-deals/ it should redirect to [blah.com...] however it does not

If you take the dash out so you get www.blah.com/latedeals/ this doees redirect to [blah.com...]

So what i was trying to get at what do i need to add to our htaccess code to make it redirect to the canonical url

Does this make sense

Pete

jdMorgan

12:57 pm on Aug 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> If someone types in www.blah.com/late-deals/ it should redirect to http://www.blah.com/late-deals/ however it does not.

I may be blind, but I see no difference in the two paths highlighted above. It appears that you want to redirect this URL to itself.

Given that initial point of confusion, it's difficult to continue. Discussing mod_rewrite is by definition, an exercise in precision and detail.

If you mean the "http://" part, then that is irrelevant, because the browser will prepend the URL with "Http://" before sending the request; The request cannot be sent at all without specifying a protocol, so the browser must do this, and the default protocol for Web browsers is HTTP. So, it's irrelevant, unless your browser has a serious problem...

If your code fails because there is a dash present in the requested URL-path, but works when no dash is present, and the dash is truly the deciding factor, then there is something seriously wrong with your server or operating system configuration.

I'd suggest you test further, but set up a dash-neutral test where neither or both URLs contain dashes, while one path exists and the other doesn't. If you find that the code fails on paths that exist, but works when the requested path does not exist, then the problem may have to do with the server's RewriteOptions [httpd.apache.org] inherit settings.

Jim