Reputation: 88
With some modifications is possible to hide extension of the web files like http://www.abc.com/asd/zxc/ against to zxc.php but the thing I wanna do is remove file names completely from the url like http://www.abc.com/asd/
it doesn't matter user where to go in web site but the url should be stay static all the time.
Is it possible to do that with .htaccess
?
I already tried this but it didn't work:
RewriteOptions inherit
RewriteEngine On # enables url rewriting
RewriteCond %{REQUEST_FILENAME} !-d # if requested uri is not directory (!-d)
RewriteCond %{REQUEST_FILENAME}\.php -f # and if there is a file named URI+'.php' (-f)
RewriteRule ^(.*)$ $1.php # then if there is any thing in uri then rewrite it as uri+'.php'
Upvotes: 1
Views: 233
Reputation: 29991
I'm not sure, but isn't the problem that you would like to check so the supplied url fragment is not a directory and not a file, and if that's the case, append .php
to the fragment?
Something like this might work:
RewriteEngine On # enable mod_rewrite
RewriteBase / # set the 'base' for the rewrite
# you might need to modify this one.
RewriteCond %{REQUEST_FILENAME} !-f # not a file
RewriteCond %{REQUEST_FILENAME} !-d # not a directory
RewriteRule ^(.*)$ /$1\.php [L] # append '.php' to the path
#
If you have the following directory structure, and of course the .htaccess
file in the root of the structure:
/code/test.php
/index.php
You should be able to access the test.php
and index.php
files by using the following urls:
http://example.com/code/test/
and
http://example.com/index/
The example.com
needs to be change to a valid domain or ip address.
Upvotes: 1