0

I was wondering how I could hide filename completetely from url using .htaccess.

Currently it is like: mysite.com/foldername/filename

And I would like it to be like: mysite.com/foldername

At the moment I use .htacces file for removing only file extensios from url and I would like to upgrade it to only show folder name. We have not leader anything about .htacces yet so I would appreciate pretty direct codes and hints, thank you! :)

RewriteOptions inherit
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.html -f 
RewriteRule ^(.*)$ $1.html

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.htm -f 
RewriteRule ^(.*)$ $1.htm

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^/?$ "http\:\/\/tjmediaproductions\.com\/quiz\/" [R=301,L]
4

1 回答 1

5
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'

others are the same
and about the las part idont know.

<br />
<br />

and there is another point and question
as you said
Currently it is like: mysite.com/foldername/filename
And I would like it to be like: mysite.com/foldername
tell me what kind of rule is behind it?
do you want to have this

    mysite.com/something

insted of

    mysite.com/something/something.php

or use

    mysite.com/something

insted of

    mysite.com/something/anotherthing.php

if you want to use first way.
you can use this may be works

    RewriteCond %{REQUEST_FILENAME} -d  # if requested uri is directory (-d)
    RewriteCond %{REQUEST_FILENAME}\.php !-f # and if there is not a file (!-f)
    RewriteRule ^([A-Za-z0-9-]+)/?$ $1/$1.php [NC,L] # foldername/foldername.php

or maybe this

    RewriteCond %{REQUEST_FILENAME} !-d  # if requested uri is not directory (!-d)
    RewriteRule ^([A-Za-z0-9-]+)/?$ $1/$1.php [NC,L] # foldername/foldername.php

于 2013-03-30T18:54:33.667 回答