I have a fairly good grasp of mod_rewrite and have been attempting to remap some old .html files back to a new WordPress page.
The main problem I have is that a 301 redirect won't work for the client. There was extensive SEO done to the old URL by someone other than me. A 301 redirect works just fine to get human visitors to the right page, but the search engines have dropped their page rankings and the traffic has died off along with sales of their lesbian novels.
Most specifically I need to internally serve /lesbian-novels.html as /lesbian-novels/ which is a valid WordPress page.
When I got to the problem there was the Simple Redirect Plugin installed on top of some .htaccess 301 Redirects.
Case #1 has the default .htaccess rules and all redirection plugins disabled. I wrote a custom 404 function to dump all relevant environmental variables containing the word 'lesbian' which is what this first output is:
$ lynx -dump http://www.susangabriel.com/lesbian-novels.html
...
REQUEST_URI /lesbian-novels.html
REDIRECT_SCRIPT_URL /lesbian-novels.html
REDIRECT_SCRIPT_URI http://www.susangabriel.com/lesbian-novels.html
SCRIPT_URL /lesbian-novels.html
SCRIPT_URI http://www.susangabriel.com/lesbian-novels.html
REDIRECT_URL /lesbian-novels.html
$ lynx -head -dump http://www.susangabriel.com/lesbian-novels.html
HTTP/1.0 404 Not Found
Date: Sun, 30 Dec 2012 23:59:04 GMT
Server: Apache
X-Powered-By: PHP/5.3.15
P3P: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"
Set-Cookie: Cart66DBSID=KAYB464P33I10BGZIZ9V201OGZP0NA9IK8THDQEB; path=/
X-Pingback: http://www.susangabriel.com/xmlrpc.php
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Cache-Control: no-cache, must-revalidate, max-age=0
Pragma: no-cache
Connection: close
Content-Type: text/html; charset=UTF-8
Basically this is the default .htaccess for the chosen permalink structure /%category%/%postname%/
$ grep -v ^# .htaccess
AcceptPathInfo On
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Case #2 I added simple added rule to rewrite requests for /lesbian-novels.html to /lesbian-novels/ which is a valid URL within WordPress:
$ lynx -head -dump http://www.susangabriel.com/lesbian-novels/
HTTP/1.0 200 OK
Date: Mon, 31 Dec 2012 00:12:04 GMT
Server: Apache
X-Powered-By: PHP/5.3.15
P3P: CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"
Set-Cookie: Cart66DBSID=VVIZ2CIUCYNWZKICOUSHA06UN2LTKZ351REKVC8C; path=/
X-Pingback: http://www.susangabriel.com/xmlrpc.php
Connection: close
Content-Type: text/html; charset=UTF-8
$ cat .htaccess
AcceptPathInfo On
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} lesbian\-novels\.html
RewriteRule ^(.*)\.html$ /$1/ [PT]
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# Pass-through the rewrite so it gets processed
# as /lesbian-novels/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
$ lynx -dump http://www.susangabriel.com/lesbian-novels.html
...
REQUEST_URI /lesbian-novels.html
REDIRECT_REDIRECT_SCRIPT_URL /lesbian-novels.html
REDIRECT_REDIRECT_SCRIPT_URI
http://www.susangabriel.com/lesbian-novels.html
REDIRECT_SCRIPT_URL /lesbian-novels.html
REDIRECT_SCRIPT_URI http://www.susangabriel.com/lesbian-novels.html
SCRIPT_URL /lesbian-novels.html
SCRIPT_URI http://www.susangabriel.com/lesbian-novels.html
REDIRECT_URL /lesbian-novels/
So by setting the PT flag, I successfully changed the REDIRECT_URL from /lesbian-novels.html to /lesbian-novels/ and in the process created a couple new environmental variables, REDIRECT_REDIRECT_SCRIPT_URL and REDIRECT_REDIRECT_SCRIPT_URI which don't seem to do me any real good.
Case #3, I tried setting some environmental variables in the RewriteRule:
$ grep -v ^# .htaccess
AcceptPathInfo On
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} lesbian\-novels\.html
RewriteRule ^(.*)\.html$ /$1/ [PT,E=PATH_INFO:/$1/,E=REQUEST_URI:/$1/,E=REDIRECT_REDIRECT_SCRIPT_URL:/$1/,E=REDIRECT_SCRIPT_URL:/$1/,E=SCRIPT_URL:/$1/]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
$ lynx -dump http://www.susangabriel.com/lesbian-novels.html
...
404 Not Found
REQUEST_URI /lesbian-novels.html
REDIRECT_REDIRECT_SCRIPT_URL /lesbian-novels/
REDIRECT_REDIRECT_SCRIPT_URI
http://www.susangabriel.com/lesbian-novels.html
REDIRECT_REDIRECT_PATH_INFO /lesbian-novels/
REDIRECT_REDIRECT_REQUEST_URI /lesbian-novels/
REDIRECT_REDIRECT_REDIRECT_REDIRECT_SCRIPT_URL /lesbian-novels/
REDIRECT_REDIRECT_REDIRECT_SCRIPT_URL /lesbian-novels/
REDIRECT_SCRIPT_URL /lesbian-novels/
REDIRECT_SCRIPT_URI http://www.susangabriel.com/lesbian-novels/
SCRIPT_URL /lesbian-novels/
SCRIPT_URI http://www.susangabriel.com/lesbian-novels/
REDIRECT_URL /lesbian-novels/
And that's where I'm stuck. I've tried various flags in the RewriteRule to get the desired behavior but everything kicks back a 404 unless I use a 301 redirect which doesn't solve the client's AWOL SEO linkage.