Welcome to WebmasterWorld Guest from 54.160.131.144

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Redirecting URL without trailing slash to one with the slash

     

jdbnd

2:20 pm on Apr 21, 2009 (gmt 0)

5+ Year Member



Anybody have a quick and clean way to use htaccess to effect the following 301 redirect?

http://www.example.com/exampleurl

TO

http://www.example.com/exampleurl/

? Google Webmaster tools sees them as separate pages and I am trying to stave off a dupe content penalty....

I only need it for that one URL, not a blanket rule.

Thanks!

Joe

g1smd

8:47 pm on Apr 21, 2009 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Is the URL for a real folder in the server filesystem, or is it a 'virtual' URL that is fed into a rewrite?

One way is:

RewriteRule ^somepath$ http://www.example.com/somepath/? [R=301,L]

but that may not be the best way at all.

Be aware that order of processing may not be what you expect if you have other redirects on your site, and those redirects use

Redirect
or
RedirectMatch
in them. Use
RewriteRule
for all of them.

jdbnd

11:22 am on Apr 24, 2009 (gmt 0)

5+ Year Member



The URL is a "virtual" URL - http://www.example.com/pretty-sounding-filename-without-extension/

Why do you say that that RewriteRule you offered may not be the best way?

I do not use Redirect anywhere.

Thanks,
Joe

jdbnd

11:29 am on Apr 24, 2009 (gmt 0)

5+ Year Member



If I use that line above, does "somepath" need the leading slash, or not?

/url
url

Joe

g1smd

2:52 pm on Apr 24, 2009 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



If the code goes in .htaccess then omit the leading slash from the rule pattern.

Include it only of the rule is going into the httpd.conf file.

You are also almost always better off redirecting to strip trailing slashes from extensionless URLs, rather than adding them

jdbnd

2:56 pm on Apr 24, 2009 (gmt 0)

5+ Year Member



Why is it preferable to strip slashes?

Thanks,
Joe

g1smd

7:12 pm on Apr 24, 2009 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



A URL that ends in a trailing slash specifies that it is really a folder on the server.

URLs without a trailing slash - when they match a real folder name in the filesystem - are redirected to add that slash back on.

An extensionless URL should be just that, ending in nothing (no extension, no dot, and no trailing slash either).

 

Featured Threads

Hot Threads This Week

Hot Threads This Month