Page is a not externally linkable
- Code, Content, and Presentation
-- Apache Web Server
---- Dynamic Query String to Static URL


g1smd - 11:39 am on Jan 19, 2013 (gmt 0)


For clarity, the target of each rule that redirects should contain protocol and hostname too.

RewriteCond %{REQUEST_URI} index.php
RewriteRule .* http://www.example.com/ [R=301,L]

simplifies to
RewriteRule index\.php http://www.example.com/ [R=301,L]
This redirects to www (but following rules redirect to non-www!) and does not check THE_REQUEST, so this rule could generate an infinite loop. Also missing escaping of literal period.

Rule 2: The [NC] flags are redundant. This rule redirects to non-www whereas Rule 1 redirects to www. Both rules should do the same. The non-www/www rule should also be the LAST of the redirects.

Rule 3: The "add a slash" rule should include the protocol and hostname in the rule target and should be listed before the catch-all non-www/www canonicalisation rule.

Rule 4: This rule should include the protocol and hostname in the rule target and should be listed before the catch-all non-www/www canonicalisation rule. Rather than test REDIRECT_STATUS you should test THE_REQUEST for direct external requests for .php URLs. Many previous posts show the code you need.

Rule 5: The [^/]$ scares me, but the rule should work.

You'll need to add another rule for your "parameters URL request" to "friendly URL" redirect. That rule will need to be before the non-www/www canonicalisation rule. The rule target should include protocol and hostname. It will also need to test THE_REQUEST to be sure the parameters were in the external URL request and not as a result of as previous internal rewrite. The code sample you supplied seems incomplete as $1 and %1 are always undefined.


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