Forum Moderators: phranque
http://www.example.com/archive/2007/08/29/New_Vancouver_Canucks_Jerseys!?p=2007/08/29/New_Vancouver_Canucks_Jerseys_ which I want to resolve to
http://www.example.com/archive/2007/08/29/new_vancouver_canucks_jerseys/ Problem I'm running into is that I have both a ! and ? in the url and it refuses to redirect. If I remove those 2 characters from the url it resolves fine using a wildcard. Any help on this would be greatly appreciated. Thanks
[edited by: jdMorgan at 2:46 pm (utc) on May 7, 2009]
[edit reason] example.com [/edit]
RewriteCond %{QUERY_STRING} ^p=1$
RewriteRule /archive/2007/08/29/New_Vancouver_Canucks_Jerseys\!^$ http://www.example.com/archive/2007/08/29/new_vancouver_canucks_jerseys/ [R=301,L]
[edited by: jdMorgan at 2:46 pm (utc) on May 7, 2009]
[edit reason] example.com [/edit]
RewriteCond %{QUERY_STRING} ^p=2007/08/29/New_Vancouver_Canucks_Jerseys_$
The problem may also be related to the exclamation point itself, and the encoding/un-endcoding of that character. To see if that is the problem, you could always try leaving the end-anchor off the rule pattern, to match any requested URL path that starts with "/archive/2007/08/29/New_Vancouver_Canucks_Jerseys" and ignore anything that follows:
RewriteRule ^/archive/2007/08/29/New_Vancouver_Canucks_Jerse[b]ys[/b] http://www.example.com/archive/2007/08/29/new_vancouver_canucks_jerseys/ [R=301,L]
Jim
RewriteCond %{QUERY_STRING} ^p=2007/08/29/New_Vancouver_Canucks_Jerseys_$
RewriteRule ^/archive/2007/08/29/New_Vancouver_Canucks_Jerseys http://www.example.com/archive/2007/08/29/new_vancouver_canucks_jerseys/ [R=301,L]
Any more ideas as to how I can tackle this?
Do you have any other working rules? -- Do you have the required "Options" and "RewriteEngine on" directives ahead of your RewriteRules?
Is this the exactly-correct and complete URL and query that you wish to redirect?
example.com/archive/2007/08/29/New_Vancouver_Canucks_Jerseys!?p=2007/08/29/New_Vancouver_Canucks_Jerseys_
Do you wish to remove the query string appended to the originally-requested URL? If so, add a question mark at the end of the new URL in the RewriteRule.
Jim
# BEGIN WPSuperCache
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
AddDefaultCharset UTF-8
RewriteCond %{REQUEST_URI} !^.*[^/]$
RewriteCond %{REQUEST_URI} !^.*//.*$
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP:Cookie} !^.*(comment_author_¦wordpress¦wp-postpass_).*$
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz -f
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz [L]
RewriteCond %{REQUEST_URI} !^.*[^/]$
RewriteCond %{REQUEST_URI} !^.*//.*$
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP:Cookie} !^.*(comment_author_¦wordpress¦wp-postpass_).*$
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html -f
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html [L]
</IfModule>
# END WPSuperCache
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
It is kinda the right URL, only my url has "what the fudge" shortform in it, which was getting replaced by the forum automatically when I pasted it it, so I took it out so as not to further muddy the issue.
I do wish to remove the query string at the end, it has no reason to be a query string. Obviously my old CMS let that page resolve, so it got indexed in google.
To avoid undesirable results, always put all of your external redirects before any of your your internal rewrites, in order from most-specific patterns --and conditions-- (fewest URLs affected) to least-specific pattern (more URLS affected), followed by your internal rewrites, again in order from most-specific pattern to least-specific pattern.
As you describe your rule-order now, your WP rewrite (your third ruleset) will be invoked for any and all requested URLs which do not resolve to a physically-existing file. As a result, your new redirect will never execute if it follows the WP rule.
Jim
RewriteCond %{REQUEST_URI} ![^/]$
RewriteCond %{REQUEST_URI} !//
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} ![=]
RewriteCond %{HTTP:Cookie} !(comment_author_¦wordpress¦wp-postpass_)
RewriteCond .gz>%{HTTP:Accept-Encoding} ^((\.gz)>.*gzip¦\.gz>)
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html%2 -f
RewriteRule ^(.*)$ /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html%2 [L]
Here, requests from clients which do accept gzipped contents will result in %2 being defined as ".gz" and inserted into the substitution URL-path. If the request is from a client which does not accept gzipped content, then %2 will be blank, and nothing will be added to the end of the substitution URL-path.
This saves repeatedly processing all the preceding conditions, and prevents a redundant and wasteful call to the OS filesystem to do a second "file-exists" check. Additional minor tweaks for efficiency.
You can also get rid of the redundant lines
</IfModule>
#
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
And strictly speaking, the <IfModule> conatiner isn't even needed, unless you plan to deploy this code on several servers, some of those servers do not support mod_rewrite, and you want the code to fail silently on those servers.
It's a good investment to make your configuration code as efficient as possible. Doing so can put off a forced upgrade to a better/more expensive server and/or hosting account as your traffic grows over time.
Jim
[edited by: jdMorgan at 7:14 pm (utc) on May 7, 2009]
RewriteEngine On
RewriteBase /RewriteCond %{QUERY_STRING} ^p=2007/08/29/New_Vancouver_Canucks_Jerseys_$
RewriteRule ^/archive/2007/08/29/New_Vancouver_Canucks_Jerseys http://www.example.com/archive/2007/08/29/new_vancouver_canucks_jerseys/ [R=301,L]
# BEGIN WPSuperCache
AddDefaultCharset UTF-8
RewriteCond %{REQUEST_URI} ![^/]$
RewriteCond %{REQUEST_URI} !//
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} ![=]
RewriteCond %{HTTP:Cookie} !(comment_author_¦wordpress¦wp-postpass_)
RewriteCond .gz>%{HTTP:Accept-Encoding} ^((\.gz)>.*gzip¦\.gz>)
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html%2 -f
RewriteRule ^(.*)$ /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html%2 [L]
# END WPSuperCache
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
[edited by: jdMorgan at 2:15 am (utc) on May 8, 2009]
[edit reason] Disabled graphic smileys in code, example.com [/edit]