Hide index.php (or index.html) of an URL

2019-01-26 12:54发布

When I type the address of my site in a browser (mysite.com), it redirects to mysite.com/index.php. Why not to index.html ? Because I changed it in the conf file in Apache 2.2 .

  • Now I would like to hide the last "index.php" part. How do I do that ?
  • Would it be different it was index.html than index.php ?

Wouldn't be ugly if by looking for google, you would end up on www.google.com/index.html ? ... it's just for esthetics but god is it important to certain people.

4条回答
女痞
2楼-- · 2019-01-26 13:27

You can easily do this with URL mapping in either the http.conf file or individual .htaccess files in your application directories. Turn on mod rewrite. Here is a simple tutorial.

查看更多
在下西门庆
3楼-- · 2019-01-26 13:33

I don't know why you need to use mod_rewrite. On my site I did nothing to hide index.php, I just don't point it anywhere in code, so instead of www.example.com/index.php?task=forum I just write www.example.com/?task=forum. It works on standard apache config.

查看更多
▲ chillily
4楼-- · 2019-01-26 13:38

This seemed to work in my environment (would NOT display index.php):

        <form action="." method="POST">
       E-mail: <input type='password' size='50' name='email' />
       <input type='submit' value='Login' />
    </form>
查看更多
淡お忘
5楼-- · 2019-01-26 13:44

If it's redirecting, (by sending a new Location on HTTP header, for example) then there's nothing you can do but changing the code that's doing the redirect.

On the other hand, if your WebServer is Apache, there is a configuration directive that might help:

DirectoryIndex

When you set that to: index.php or index.html, then your web server will automatically redirect to those internal files without changing the URL when you hit the directory on your server where the DirectoryIndex directive is setup.

I guess you'll get better answers if you post this on SERVERFAULT.

Good luck.

查看更多
登录 后发表回答