Tutorial :How can I rewrite all urls to “/”?



Question:

Server: Apache

I'm looking to rewrite my urls in the following way, and I can't figure out a way to get it to work.

http://website.com/index.html  

I want it to redirect to:

http://website.com/  

So basically I want to load index.html, but not display it in the url. I also don't want to give it another name. I'm not looking for /index.html to become /index

Additionally, I'm trying to have any GET data such as:

http://website.com/index.html?id=0&name="fred"  

To rewrite to:

http://website.com/?id=0&name="fred".  

If you have a solution that is not using .htaccess files that's fine as well.


Solution:1

I believe this should work:

RewriteEngine on  RewriteRule ^index\.html(.*)$ /$1 [R=permanent,L]  

This will redirect any requests that start with /index.html to simply "/" and will preserve any arguments that come after index.html


Solution:2

For a .htaccess file:

RewriteEngine on  RewriteCond %{THE_REQUEST} ^GET\ /index\.html  RewriteRule ^index\.html$ / [L,R=301]  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »