Page is a not externally linkable
jasimon9 - 6:12 pm on Jan 21, 2013 (gmt 0)
Thanks for your swift and detailed response. Almost more than one can hope for these days!
I am talking about servers. In fact I omitted that the same set of rewrite rules is also working perfectly on a development server which is on FreeBSD, Apache 2.2.21. Our production server is also FreeBSD, Apache 2.2.19. Normally we try to keep everything at the same level, but this time they have gotten a bit out of sync.
The Mac environment is "pre-development" where I was just doing some testing. Unfortunately, the Windows environment is where I debug, as I have not succeeded in migrating away from that yet.
In any case, I came up with the 4 lines from your "canonical" reposting at [webmasterworld.com...] dated 10:27 am on June 13, 2012. In that posting you presented Part 1, Part 2 (and Part 0), as follows:
Part 1
RewriteCond %{THE_REQUEST} \?
RewriteCond %{QUERY_STRING} queryname=([a-z]+)
RewriteRule longcomplicatedURL http://www.example.com/blahblah/%1? [R=301,L]
Part 2
RewriteRule blahblah/([a-z]+)$ longcomplicatedURL?queryname=$1 [L]
So I concluded that both parts are needed, giving the 4 lines that I have, adapted to my situation. I realize that you were trying to illustrate the principle as you noted that "in real life it will usually be a little more complicated, but that's the basic process."
My situation is not typical in that I do not need to take part of the query string in the regex and use it in the rewrite. However, I was hoping that the same method would be applicable.
As an aside, because I do not require the regex replacement, another approach would be to just rename the actual pages, and use a redirect from the old name to the new name. This could be simpler, but goes into other SEO areas I am not fully comfortable with. Plus there are variations in which other GET vars are used in addition to what is handled by the redirect. Yet if I became comfortable with this approach, it could be viable.
Regarding the duplicate trailing brackets, I am embarrassed to say that in fact they were place in the Mac and FreeBSD instances, but not in the Windows instance. Which means that while they are wrong, they are not causing the looping. After removing them, the Mac and FreeBSD instances continue to function as expected. Windows instance, being unchanged, still loops.
Regarding transforming "long complicated query strings" into "short pretty ones": I am actually transforming some fixed query strings into a fairly long but keyword rich filenames. The point is that the original names to not tell the search engines anything about the content.
Point taken about the added NC.
The extra / was put in during initial debugging of the Windows version.
The "infinite loop" is referring to internal. In fact, the looping is visible in the rewrite log.
None of this is using htaccess; everything is in httpd-vhosts.conf. I tried both with and without the leading directory. On our production servers there are many other rewrite rules which have been in place for a long time and work fine. mod_alias is not in use. Those other rewrite rules were put in place by an expert sysadmin with long experience. They do not have leading directory slashes in any of the patterns, nor do they have the protocol plus domain. Here is an example of one of those rules, which has been in effect since 2006:
RewriteRule ^main.asp /index.php [L,NC,R]
However, on my test servers on the Mac and Windows, there are no other rewrite rules. Only the ones I am trying to develop now. So I don't think there is any interference for other rules.
You gave a lot of information, some of which I have assimilated; other parts I am not sure I have the understanding.
Bottom line of my current understanding: the following original sample should be changed from
RewriteCond %{THE_REQUEST} \?
RewriteCond %{QUERY_STRING} ^mode=create&usertype=pri$
RewriteRule ^register\.php$ /manufacturers-sales-reps-register.php? [NC,L,R=301]]
RewriteRule ^manufacturers-sales-reps-register\.php /register.php/?mode=create&usertype=pri [L,NC]
to the following:
RewriteCond %{THE_REQUEST} [A-Z]{3,9}\ /register\.php\?mode=create&usertype=pri\ HTTP
RewriteRule ^register\.php$ /manufacturers-sales-reps-register.php? [NC,L,R=301]
RewriteRule ^/manufacturers-sales-reps-register\.php http://www.example.com/register.php?mode=create&usertype=pri [L]
Specifically, the changes here the following:
1. Combine the two conditions into one.
2. Correct the typo of the two ]] in the first rewrite rule
3. Add a leading slash to the pattern of the second rewrite rule (because using a vhost not htaccess)
4. Remove the trailing slash from the target in the second rule
5. Add the protocol and domain to the second rewrite rule (with the actual domain in place of "example")
6. Remove the NC from the second rewrite rule
Thank you again!