1

I want to hide any request on the following php file to www.example.com/.

    www.example.com/index.php  to www.example.com/     (hide index.php)
    www.example.com/content.php to www.example.com/    (hide content.php)
    www.example.com/welcome.php to www.example.com/    (hide welcome.php)

Note: I just want to hide the file without redirecting them. For example, hide the part on index.php or content.php without redirect them to www.example.com/.

I tried

RewriteEngine On

RewriteCond %{THE_REQUEST} ^\w+\ /(.*)\.php(\?.*)?\ HTTP/
RewriteRule ^ http://%{HTTP_HOST}/%1 [R=301]

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .* $0.php

I also tried

DirectoryIndex index.php
DirectoryIndex content.php
DirectoryIndex welcome.php

These code didn't seem to work. Any idea? Sorry, i'm very new to this.

Nick
  • 315
  • 2
  • 9
  • 17

1 Answers1

3

If I recall correctly something like this should work correctly.

RewriteRule ^/index.php$ http://www.example.com/ [R,NC,L]
RewriteRule ^/content.php$ http://www.example.com/ [R,NC,L]
RewriteRule ^/welcome.php$ http://www.example.com/ [R,NC,L]

Kind regards,
Bo

Bo.
  • 2,547
  • 3
  • 24
  • 36
  • Thank you, this works. However, is there anyway to just hide index.php or content.php without redirecting the user to another URL? – Nick May 23 '12 at 13:14
  • 2
    @Nick No, not with mod_rewrite. It has two main purposes: 1) serve a different page without changing the URL (often used for "pretty print" of URLs) or 2) redirect the user to a completely different URL. If you really need that functionality (although I'd question why) then you might have some luck with JavaScript on the client side, e.g. http://stackoverflow.com/a/1465/283242 – IBBoard May 23 '12 at 13:24
  • Thanks a lot Bo. You help me a lot. The reason is that I'm doing facebook application and I dont want user to see where my files located. – Nick May 23 '12 at 13:37