0

I have this code

RewriteCond %{THE_REQUEST} /index\.html? [NC]
RewriteRule ^(.*/)?index\.html?$ /$1 [R=301,L]

Where is to place this code on my index.html sites?.I have my

"www.text.com/index.html"

and i need to redirect to

"www.text.com"

cssyphus
  • 37,875
  • 18
  • 96
  • 111
uttar.ya
  • 3
  • 4

2 Answers2

0

You need to create a .htaccess (plain text) file in the same folder as your index.html Note that there is no first part, just dot-htaccess.

The code in your question is typical htaccess script.

Note that htaccess files only work for Apache webservers, which are the ones typically used on shared hosting systems like GoDaddy, HostGator, etc - and also on XAMPP, WAMP, MAMP, LAMP

cssyphus
  • 37,875
  • 18
  • 96
  • 111
0

In my first answer I did not check your htaccess code. I notice that this line was missing from top of the code:

RewriteEngine On

So, it would look like:

RewriteEngine On
RewriteCond %{THE_REQUEST} /index\.html? [NC]
RewriteRule ^(.*/)?index\.html?$ /$1 [R=301,L]

If that doesn't work, try one of these:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

or

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]

Sources:

htaccess remove index.php from url

Remove 'index.php' from URL with .htaccess

Community
  • 1
  • 1
cssyphus
  • 37,875
  • 18
  • 96
  • 111
  • I am using html code..will this one works? RewriteEngine On RewriteCond %{THE_REQUEST} /www.index\.html? [NC] RewriteRule ^(.*/)?www.index.html?$ /$1 [R=301,L]...?..i need to point to root rather than www.index.com/html.. – uttar.ya May 20 '16 at 01:20
  • Try it. Refresh your page and see what happens. If that doesn't do what you want, delete the `.htaccess` file and post another question with a more detailed request -- what you tried, and what happened, and what you need it to do. When you accept an answer *(by checkmarking an answer)* and open another question, you will have dozens of new people looking at the question trying to help. Just make sure that you use the correct tag ***(.htaccess)*** so that the experts in that area will notice your question. *Also, tell us what kind of system your web page is on so we know if .htaccess will work* – cssyphus May 20 '16 at 01:39
  • I've tried all it doesn't work for me on my .htaccess file:( – uttar.ya May 20 '16 at 05:26
  • What kind of system is your website hosted on? `htaccess` files do not work on Microsoft's `.asp / .aspx / .Net` hosts. However, most of the web is run on LAMP, which use `.htaccess` files. If on an Apache web server (very common with shared hosting), then I suggest asking a follow up question. On StackOverflow, you get points for each closed question (when you accept an answer) and the correct answer is also rewarded points - so tons of people are *trying* to answer questions. Every new question gets *dozens* of immediate views -- keep asking / checkmarking / asking again until solved. – cssyphus May 20 '16 at 13:16
  • My website is hosted on Godaddy. i tried all those answers above still not working.It will take longer to updates on google?or once i made a changes it will automatically updated?.For your code above i only replace the index.php to index.html – uttar.ya May 22 '16 at 22:28