Redirect non www to www and index.html to root (Subfolder)

I want to redirect non www to www and index.html to root but it is not working, But when I type http://mydomain.net/about-us.html it redirects to http://www.mydomain.net/html/about-us.html

[B]Actually my site html pages are stored in subfolder named HTML
eg

/(Root)
HTML
about-us.html
index.html[/B]

I am using this code, but getting error when I type http://mydomain.net/about-us.html it redirects to http://www.mydomain.net/html/about-us.html

RewriteEngine On

RewriteCond %{HTTP_HOST} !^(www\.mydomain\.net)?$
RewriteRule (.*) http://www.mydomain.net/$1 [R=301,L]

RewriteCond %{THE_REQUEST} [1]{3,9}\ /([^/]+/)index\.html?\ HTTP/
RewriteRule ^(([^/]+/)
)index\.html?$ http://www.mydomain.net/$1 [R=301,L]


  1. A-Z ↩︎

setjo,

From your description, your HTML and html files are OUTSIDE the webspace defined by (Root). Therefore, you should not be able to access them using the virtual host as shown. Simply move your HTML directory and .html files into the (Root) directory and you’ll be set.

As for your mod_rewrite code, please allow a few constructive comments:

RewriteEngine On

RewriteCond %{HTTP_HOST} !^(www\\.mydomain\\.net)?$
# because you're not using the %1 variable created by the (..), delete the parentheticals (MINOR machine cycle saver)
RewriteRule (.*) http://www.mydomain.net/$1 [R=301,L]
# I prefer to use the Apache variable {%REQUEST_URI} rather than capture it in $1, therefore, I use
# RewriteRule .? http://www.mydomain.net%{REQUEST_URI} [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\\ /([^/]+/)*index\\.html?\\ HTTP/
# OMG! No need to capture all that @#$% (again, you're not using it) so I would use
# RewriteCond %{THE_REQUEST} index\\.html
RewriteRule ^(([^/]+/)*)index\\.html?$ http://www.mydomain.net/$1 [R=301,L]
# only one / but it's all optional? Loopy (on www.mydomain.net/index.html)!!! Make the * a + and you'll be okay
# ... UNLESS your host requires Apache to display the DirectoryIndex.
# Personally, I don't like stripping the DirectoryIndex filename but that's just me.

Regards,

DK