Page is a not externally linkable
- Code, Content, and Presentation
-- Apache Web Server
---- htaccess rewrite help


jdMorgan - 9:11 pm on Feb 7, 2011 (gmt 0)


To fix the originally-posted problem, something like:

RewriteCond %{QUERY_STRING} ^m=h&page=([0-9])+(/page=[0-9]+)+$
RewriteRule ^$ http://www.example.com/top_rated/page%1 [R=301,L]
#
RewriteCond %{QUERY_STRING} ^m=m&page=([0-9])+(/page=[0-9]+)+$
RewriteRule ^$ http://www.example.com/most_viewed/page%1 [R=301,L]

The posted code is far too long and has been re-posted too many times to get much sustained attention here. It could be significantly shortened (and sped up) by combing rules such as

RewriteRule ^category/$ http://www.example.com/category [R=301,L]
RewriteRule ^tag/$ http://www.example.com/tags [R=301,L]
... 28 more rules ...
RewriteRule ^blog/$ http://www.example.com/blog [R=301,L]
RewriteRule ^profile/$ http://www.example.com/profile [R=301,L] ]

into a single rule:

# Externally redirect to remove trailing slashes from all specified extensionless URL-paths
RewriteCond $1 ^(blog(_(drafts|queue))?category|tag|popular_tags|webmasters|contact|about|subscriptions|favorites|disabled|search-stats|(channel|title)-editor|seo-tools|import-(failed|profile|queued)|queued|most_(recent|viewed|discussed)|top_rated|featured|directory|search|stats|log(out|in)|lostpw|register)$
RewriteRule ^(.+)/$ http://www.example.com/$1 [R=301,L]

or the much-less-efficient, but easier-to-maintain:

# Externally redirect requests for all URL-paths ending in "/" unless
# the requested URL-path resolves to a physically-existing directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ http://www.example.com/$1 [R=301,L]

In the first version, it is assumed that most requests to this server do not end in "/". Therefore, the specific URL-path testing is done in a separate RewriteCond, which will not be evaluated at all unless the (far simpler) RewriteRule pattern matches first (see mod_rewrite Rule Processing documentation for details).

The second version is less efficient because it calls the OS to go check the filesystem for each requested URL-path ending in a slash. This may require the physical disk to be checked, which is very slow (and hard on the disk if there are a lot of such checks). But you must decide whether that is a better or worse trade-off than maintaining this list of slashed URLs that need to be redirected to remove the slashes -- or not.

Jim


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