| Welcome to WebmasterWorld Guest from 184.108.40.206 |
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
|Become a Pro Member|
|Redirecting URL without trailing slash to one with the slash|
Anybody have a quick and clean way to use htaccess to effect the following 301 redirect?
? 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.
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
RedirectMatch in them. Use
RewriteRule for all of them.
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.
If I use that line above, does "somepath" need the leading slash, or not?
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
Why is it preferable to strip slashes?
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).
All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved