Page is a not externally linkable
- Code, Content, and Presentation
-- Apache Web Server
---- Simple 301 redirect and Wordpress htaccess rules


agneslesage - 2:44 pm on Aug 9, 2010 (gmt 0)


ouf....
I am not sure I got it all right...

1> I ve added a question mark at the end of the first redirect for the default to index

RewriteRule ^default\.asp$ http://www.atable.com/? [R=301,L]


2> I ve changed the index and default to what you said

# Redirect direct client requests for URL-path /index.php to / and for /folder/index.php to /folder/
# Likewise for default.php direct requests in root or in folder,
# and force www and strip parameters at same time, to avoid duplicate content.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*(index|default)\.(php|html?|asp)([?#][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*)(index|default)\.(php|html?|asp)$ http://www.example.com/$1? [R=301,L]


3> Now for this of yours, I dont know if I am supposed to do more...

"One problem still to solve: requests for index.php with attached parameters still produce a double redirect.
Rule ordering and scope is very important here.
Personally, I'd exclude both index and default from having their parameters stripped within the current parameter-stripping rule (or I would place it after the rule(s) dealing with default and index requests) as that avoids a double redirect for those requests.
I would modify the index redirect to handle both index and default requests, and make sure that rule also forces www and remove parameters for those requests, at the same time as stripping the index or default filename from the URL.
"

=> So the final code comes:

##### Wordpress Optimized code with my redirects ####

# Intro

RewriteEngine On
RewriteBase /

# My specific Redirect default.asp to WP Homepage
RewriteRule ^default\.asp$ http://www.atable.com/? [R=301,L]

# My Specific Redirects from old site (.asp URLs to WP+SEF-format URLs)
# One may remove the "?" at the end of the target URL to keep parameters in the string.

RewriteCond %{QUERY_STRING} ^([^&]*&)*page=qui_nous(&.*)?$
RewriteRule ^template\.asp$ http://www.atable.com/qui-sommes-nous/? [R=301,L]

# WP optimized code #

# Redirect direct client requests for URL-path /index.php to / and for /folder/index.php to /folder/
# Likewise for default.php direct requests in root or in folder,
# and force www and strip parameters at same time, to avoid duplicate content.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*(index|default)\.(php|html?|asp)([?#][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*)(index|default)\.(php|html?|asp)$ http://www.example.com/$1? [R=301,L]


# I'd add an additional redirect here to strip all parameters and force www
# for all requests with parameters that have made it thus far.

# Redirect requests for non-blank, non-canonical hostnames to canonical hostname
RewriteCond %{HTTP_HOST} !^(www\.atable\.com)?$
RewriteRule ^(.*)$ http://www.atable.com/$1? [R=301,L]

# Except for requests for /index.php and for the most-frequently-requested
# filetypes that WP cannot generate, rewrite all URL requests which do not
# resolve to an existing file or directory to the WordPress script filepath
RewriteCond $1 !^index\.php$
RewriteCond $1 !\.(gif|jpe?g|png|ico|css|js)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php [L]
# END WordPress


Thread source:: http://www.webmasterworld.com/apache/4182512.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com