Url rewrite question

With htaccess, I want to achieve 2 things:

301 redirect anybody who enters http://mydomain.com(/anything) to www.mydomain.com (note, redirects to homepage) Non www to http://www.mydomain.com

301 redirect anybody who enters http://www.mydomain.com(/anything) to www.mydomain.com (note, redirects any subpage to homepage

So basically anything other than a direct call to http://www.mydomain.com will 301 redirect you to homepage (http://www.mydomain.com).

So, yes, this is just a 1 page site.

Hope that makes sense.

Thank you.

LB,

Specificity: You want to:

  1. Force www “subdomain” in your links

and

  1. Redirect EVERYTHING to your DirectoryIndex (which I have to assume is index.php - I also have to assume that you’ll want to retain the request as “link” in a query string althrough PHP can look at {THE_REQUEST}).
RewriteEngine on

# #1
RewriteCond %{HTTP_HOST} !^www\\.example\\.com$
RewriteRule .? http://www.example.com{REQUEST_URI} [R=301,L]
# this retains the original request while changing to www'd domain (lowercase)

# #2 - This is the query string version
RewriteCond {REQUEST_URI} !index\\.php$
RewriteRule ^(.*)$ index.php?link=$1 [L]

# #2a - This is the NON-query string version
RewriteRule !index\\.php$ index.php [L]

# #2b - Merely use ErrorDocument to redirect 404s to index.php (the handler script)
ErrorDocument 404 /index.php
# Note that the redirection MUST be absolute - this is "internal absolute"

My “insistance” on actually using the DirectoryIndex is (a) hidden and (b) prevents forcing Apache to do additional work (more cycles, more delay) for no useful purpose.

Regards,

DK