Page is a not externally linkable
jasimon9 - 4:59 am on Jan 30, 2013 (gmt 0)
Here are the prototype rules I have come up with. They seem to be working as I want, with one exception, as described below. But I am thinking maybe I can live with that. The rules assume a page called redirect.php. This page simply displays the query string parameters that it is passed, for testing.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /redirect\.php\?one=(\w+)(?:&two=(\w+)(?:&three=(\w+)(?:&four=(\w+)(?:&five=(\w+))?)?)?)?\ HTTP/
RewriteRule ^redirect\.php$ /redirected/%1/%2/%3/%4/%5? [R=301,L]
RewriteRule ^redirected/(\w+)(?:/(\w+)(?:/(\w+)(?:/(\w+)(?:/(\w+))?)?)?)?/?$ /redirect.php?one=$1&two=$2&three=$3&four=$4&five=$5 [L]
Here is what the rules do:
1. The pretty URL looks like this: redirected/a/b/c/d/e. The first parameter "a" is mandatory, but any of the trailing parameters are optional. Parameters cannot be skipped however. Another way of saying this is that any part of the "path" beyond the first level can be dropped.
2. If the "old" ugly url is used, likewise, any of the trailing parameters can be omitted in the same way.
3. Although the page works properly when parameters are omitted from the ugly url, there are "directories' named with the null-string. For example, when the url is redirect.php?mode=a&usertype=b , then the rewritten url that appears in the address bar is /redirected/a/b///. This is because the first rewrite rule has 5 hard-coded slashes.
While this is unusual appearing, I am thinking this is not a problem for the following reasons:
1. I have done some testing at well-known websites, and it appears that adding null-string named directories, ie, a couple of slashes, at the end of a url seems to not bother anything.
2. This would only occur with ugly urls coming from outside my website, which redirect to the actual page with a valid query string.
3. The problem does not occur at all with the pretty url that omits a portion of the "path".
I am wondering if this issue is merely a cosmetic alteration to the address bar, or there is something else that a server, browser, or search engine might object to.