Welcome to WebmasterWorld Guest from 54.167.46.29

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Redirecting URL without trailing slash to one with the slash

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

Junior Member

5+ Year Member

joined:Aug 27, 2008
posts: 65
votes: 0


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

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

Senior Member

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

joined:July 3, 2002
posts:18903
votes: 0


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.
11:22 am on Apr 24, 2009 (gmt 0)

Junior Member

5+ Year Member

joined:Aug 27, 2008
posts:65
votes: 0


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

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

Junior Member

5+ Year Member

joined:Aug 27, 2008
posts:65
votes: 0


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

/url
url

Joe

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

Senior Member

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

joined:July 3, 2002
posts:18903
votes: 0


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

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

Junior Member

5+ Year Member

joined:Aug 27, 2008
posts: 65
votes: 0


Why is it preferable to strip slashes?

Thanks,
Joe

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

Senior Member

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

joined:July 3, 2002
posts:18903
votes: 0


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).