How can I rewrite all urls to “/”?
-
05-07-2019 - |
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
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
OTHER TIPS
For a .htaccess file:
RewriteEngine on
RewriteCond %{THE_REQUEST} ^GET\ /index\.html
RewriteRule ^index\.html$ / [L,R=301]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow