The first is stripping the DirectoryIndex from the URI - which is NOT a smart thing to do so some hosts will not allow this redirection. That’s simply
RewriteRule ^index\\.html$ / [R=301,L]
The second one is forcing www in the {HTTP_HOST} which is already coded in my signature’s tutorial (and in this board’s stick threads) so I won’t bother to spoonfeed here.
That would work (so long as the file’s named .htaccess - notepad will add .txt and you don’t want that so be sure to change the name).
Personally, I’d use .? as the regex in the RewriteRule and replace /$1 with %{REQUEST_URI}. It does the same thing but is marginally cleaner (because you already have the (.*) atom available as %{REQUEST_URI}).
Obviously, replace the domain in your code like:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\\.earntopqualitygadgetsonline\\.co\\.uk$ [NC]
RewriteRule .? http://www.earntopqualitygadgetsonline.co.uk%{REQUEST_URI} [L,R=301]
First, I consider redirecting away from the DirectoryIndex to the directory so Apache can pick the DirectoryIndex file (index.html => /) absurd and a needless burden on Apache (small as it may be). I believe that some hosts will not allow this anyway.
Second, I’ve made it my consistent policy over the years in this forum NOT to aid “script kiddies.” Not that I’m calling you a script kiddie, please, but asking for someone to create code for you (as I’ve already done above) which you have not attempted yourself (at least you’ve shown no evidence) means that you’re not likely to learn about mod_rewrite. IMHO, using code which you do not understand is unwise so I do not support that.
In other words, SHOW your attempt and I’ll be more than willing to critique which, more often than not, results in the correct code AND the all important understanding that you’ve developed in the attempt.
Yes, thats what i want… I want it to change from “index.html” to “/” and also want it to change from without the “www” to with it. I have tryed it a good few times. I google it first and was reading it and tryed it, but it didnt work. It tryed to change the code a few times & it didnt work. Also when uploading it it was saying invalid file. I was then just asking on here to see how to do it and then compare it to what i done then fix what i done wrong.
I think this problem is called 301 htaccess redirection mostly faced in the SEO field, even i was facing that. So the thing is, you have to first know where is your site hosted like windows or linux then you need to upload that kind of code on the website. But you must be alert when you do this. So give this work only that person who has a good knowledge about this.