Forum Moderators: phranque
Also, Apache does not accept Windows-type wild-cards such as "*.*" -- Apache uses regular expressions (see our Forum Charter [webmasterworld.com] for a reference).
The search I posted above will lead you to working examples of the mod_rewrite method.
Jim
# Force www canonical hostname
RewriteCond %{HTTP_HOST} ^example\.com
rewriterule (.*) http:/[smilestopper]/www.example.com [R=301,L]
#
# Rewrite all requests to www subdirectory, but prevent rewrite looping
RewriteCond $1!^www/
rewriterule (.*) /www/$1 [L]
#
# Forbid direct-request access to /www subfolder
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /www/
rewriterule .* - [F]
We have a major problem here, in that it's impossible for members to look over each other's shoulders to examine the test results on the monitor and make suggestions while testing. We needed to know how your testing went, and what the results were... What error messages did you get, how did the results differ from your expectations, etc. So, that's what I mean when I say, "What did you mean by 'no luck'?"
Anyway, good show, and I hope that code helps you achieve your purpose.
Jim
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.site\.tld$ [NC]
RewriteRule ^(.*)$ http://site.tld/$1 [R=301,L]
...But I guess it is your site at the end of the day.
W3C is a great resource, but they sometimes ignore some realities of the Web and its infrastructure.
Jim
... I ask as a query, as I've never had the opportunity to use lbnamed personally. 8)
RewriteEngine on
RewriteCond %{http_HOST} ^example\.com
RewriteRule ^(.*) http:/[smilestopper]/www.example.com/$1 [L,R=301]
RewriteRule widgets/(.*)/(.*)/ products.php?category=$1&widgets=$2&type=widgets [L]
RewriteRule widgets/(.*)/ products.php?category=$1&type=widgets [L]
--OR--
RewriteEngine on
RewriteRule widgets/(.*)/(.*)/ products.php?category=$1&widgets=$2&type=widgets [L]
RewriteRule widgets/(.*)/ products.php?category=$1&type=widgets [L]
RewriteCond %{http_HOST} ^example\.com
RewriteRule ^(.*) http:/[smilestopper]/www.example.com/$1 [L,R=301]
General guidelines:
In the code you posted, the first point applies, but from an efficiency standpoint: The pattern ".*" is the most ambiguous, least-efficient pattern possible when used for multiple subpatterns as in "(.*)/(.*)". In this case, "([^/]+)/([^/]+)/" or "([^/]+)/([^/]*)/?" would be much faster to process (although I can't be completely sure either will work for you without knowing your entire URL-scheme.)
Negative-match patterns like "([^/]+)/([^/]+)/" can be processed from left to right in one single pass, whereas evaluating patterns like "(.*)/(.*)" requires multiple trial matches, with the number of required trials proportional to the number of characters in the requested URI.
Jim