homepage Welcome to WebmasterWorld Guest from 54.167.75.155
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Redirecting URL without trailing slash to one with the slash
jdbnd




msg:3897015
 2:20 pm on Apr 21, 2009 (gmt 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

 

g1smd




msg:3897298
 8:47 pm on Apr 21, 2009 (gmt 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.

jdbnd




msg:3899479
 11:22 am on Apr 24, 2009 (gmt 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

jdbnd




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

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

/url
url

Joe

g1smd




msg:3899669
 2:52 pm on Apr 24, 2009 (gmt 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

jdbnd




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

Why is it preferable to strip slashes?

Thanks,
Joe

g1smd




msg:3899896
 7:12 pm on Apr 24, 2009 (gmt 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).

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved