Nick
Nick

Reputation: 315

mod rewrite to hide url

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.

Upvotes: 1

Views: 11283

Answers (1)

Bo.
Bo.

Reputation: 2541

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

Upvotes: 3

Related Questions