Forum Moderators: phranque

Message Too Old, No Replies

Setting all URL's to end with backslash - is it easy to set up

         

Whitey

11:09 pm on Dec 14, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Been around a while, but an absolute "newbie" to coding, which I want to get closer to, in order to better instruct our developers, so that we eliminate duplicate content paths into our website.

Is configuring all URL's to end in a back slash, and all non www. to www a lengthy task? And is it simple to implement - could I do it?

fathom

11:57 pm on Dec 14, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Make all landing pages index.php, index.html, index.asp, etc.

Whitey

1:09 am on Dec 15, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Using an extension like .html locks you into that file format.

@lucy24 No more than going extensionless. It's the same rewrite either way.

RewriteRule ^paintings/mice/([a-jw]\w+)\.html /paintings/critters/critterlinks.php?subdir=mice&page=$1 [L,NS]

RewriteRule ^fun/CheesyNovel/chap(\d+)\.html /fun/CheesyNovel/cnlinks.php?chapter=$1&page=CheesyNovel [L]

"If I can do it, anyone can." [webmasterworld.com...] .

I prefer "/" to those extensions, but that's another story.

Any thoughts on the OP?

fathom

2:33 am on Dec 15, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



In the end, the other thread's point is pointless. There is no SEO value in the URL unless there are no links involved in the equation.

Add whatever into its own folder with the landing page index.php e.g. /folder/index.html it will default to /folder/

lucy24

2:47 am on Dec 15, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Gosh, that was a long time ago.

If your URLs end in a slash, the major search engines will assume they are directories, and will ask for all three forms:
#1 example.com/filename/
#2 example.com/filename
#3 example.com/filename/index.html
(I know this from direct personal observation.)

Make sure #2 and #3 redirect to #1, exactly as if it really were a directory. (If it were a directory, mod_dir would take care of #2, but you'd still have to code for #3.)

But, yeah, that other thread did get a bit entangled in the "how to" vs. "whether to" mess :)

Whitey

4:22 am on Dec 15, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



lol - i thought I'd jog your memory ;)

Any idea if it's a big job to set up the rewrites for this type of thing - I'm trying to get a sense of the time required and if i could do it as an absolute novice coder.

lucy24

7:49 am on Dec 15, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do you mean rewrite or do you mean redirect? Or both? There are two parts, though they're both fairly simple.

One part is rewriting (= secret stuff happening behind the scenes in your server) from your chosen URL to wherever the content really lives.

The other part is redirecting (= sending an explicit message back to the visitor) any wrong URLs. Or, if you prefer, serving up a manual 404; you have to do something to deal with the wrong requests that will invariably come in. That Other Thread had a lot to say about type-ins leaving off the final slash, so wrong requests may come from humans as well as robots.

Oh, you also asked about with/without www. That part is trivial; it uses a single RewriteRule with one condition, and is always the very last of your (external)* redirects. Forums search for "domain-name canonicalization" should bring up several hundred examples.


* If you really are new to this, note that "external" doesn't mean "involving some other domain and/or server". It just means sending a message back to the visitor, as opposed to secretly doing stuff without telling them about it.

Whitey

9:23 pm on Dec 15, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



How much time would you expect an experienced coder/administrator take to set this up, versus a novice.

I did some digging and found this:

4) Various types of redirect

The common SEO redirect is ensuring that a canonical domain is used, normally www vs. non-www. There are also a couple of other redirects you might find useful. I have kept them simple here, but often times you will want to combine these to ensure you avoid chaining redirects:

# Ensure www on all URLs.

RewriteCond %{HTTP_HOST} ^example.com [NC]

RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

# Ensure we are using HTTPS version of the site.

RewriteCond %{HTTPS} !on

RewriteRule (.*) [%{HTTP_HOST}%{REQUEST_URI}...] [L,R=301]

# Ensure all URLs have a trailing slash.

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_URI} !(.*)/$

RewriteRule ^(.*)$ http://www.example.com/$1/ [L,R=301]
[moz.com...]

I mean,
1) is there standard code, or blocks of code covering generalised 301 domain name URL variants for canonicalization that can be implemented, if so
2) what time is required to do this - minutes or hours?
3) is the above code example ok to cover the OP?
4) are the variants limitless and how can you catch all of these e.g. .com/folder//// to .com/folder/ ww1. ; to www. etc etc ; all urls lower case

lucy24

9:53 pm on Dec 15, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



what time is required to do this - minutes or hours?

For the domain name: minutes.

If you've got an HTTPS site, this can be handled in the same RewriteRule that handles with/without www. Note that the target should NEVER say %{HTTP_HOST} because the whole point of these redirects is that you're sending them to some specific hostname, whether or not the request was right all along. And it's senseless to say %{REQUEST_URI} when you've just got through capturing that same request. Assuming your preferred form is https://www.example.com the rule looks like this

RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
Note that the domain-name part is expressed as a negative: "If the hostname is anything other than the exact form I want or exactly nothing". The "exactly nothing" part (the parentheses and question mark) is a legacy from some older types of request that don't send a hostname at all. I, personally, have never seen a request without the "Host:" header; it's possible that the server adds one if it's absent (I'm on shared hosting).

Now, the trailing slash: This one is a more complicated question because it depends on
(a) what URL format you are currently using (i.e. URLs that are already known to search engines and/or used in other people's links to you)
(b) whether your existing URLs correspond to real, physical files, or at least a one-on-one correspondence like "example.com/filename" = "example.com/filename.php"
(c) whether you're now using, or formerly used, a CMS
(d) how many URLs are involved
(e) probably some other stuff that I've overlooked.

Whitey

8:01 am on Dec 18, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Any issues redirecting http: to https: . Is this a matter of minutes as well ?

lucy24

8:51 am on Dec 18, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Any issues redirecting http: to https: . Is this a matter of minutes as well ?

Seconds, probably, because you've already done it ;) See the middle of my previous post.

Whitey

5:06 am on Dec 19, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



301 a directory URL and all of its contents to another

If you have redesigned your site architecture and renamed a directory, you need to create a 301 for the entire directory. Here’s how:
RedirectMatch 301 ^/oldname/ [xyz.com...]
[internetmarketingninjas.com...] .

I'm getting a sense the following is simple, but still a few more questions:

1. If our existing site was built with the same url folder structures and names like this, but goes to lower case in the new site rewrite rules, do we additionally need to add redirects [ and code] for important pages with external linking [ I was thinking the url re write will take care of that in some way ]
e.g.
http ://www.mysite.com/Green/Blue-Widgets/ to https ://www.mysite.com/blue-widgets/

2. If the old site was http, and now goes to https, do all the sites url's with external links need to be redirected or is this catered for within the previous explanations for every single url ie does it happen automatically by default

3. https : If we hold the old url structures with upper and lower case like this onto the new site: https ://www.mysite.com/Blue-Widgets/ do we need to apply any redirects on the new site, if the only change is the https?

4. Is rewriting the first letter of a word in the folders like this /Blue-Widgets/Green-White-And-Red/ easy and again, does it take minutes

I'd like to avoid 301 redirects specifically for externally linked pages as it's a pain to identify, but we do need to preserve the influence of good inbound links to the new pages.

Showing my ignorance here - thanks for your patience !

lucy24

9:22 am on Dec 19, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



RedirectMatch

Don't use this. Redirect and RedirectMatch are mod_alias directives; they don't combine well with mod_rewrite, which you need for your domain-name redirects. Any existing redirects using mod_alias need to be changed to use mod_rewrite syntax. (This is easy.)

Case changing is not automatic. If you have your own server, you can use a built-in RewriteMap to take care of it easily. On shared hosting, this will almost certainly not be available; you will have to either redirect one-for-one, or detour to an extremely simple php script that does it for you. It just depends on how many URLs are involved.

You've already got a global http-to-https redirect. This will cover any incoming requests from humans and search engines. Your internal links should automatically fix themselves, assuming you've been wise enough to use site-absolute links (the kind beginning in / slash).

Any specific redirect, like example.com/oldpage >> example.com/newpage, will already use the correct protocol and domain name in the target, so
http://www.example.com/oldurl
>>
https://example.com/newurl
in a single step.

The http and www redirect is only for the leftovers: the requests that were correct in all other ways.